﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using System.Globalization;
using MCChuoiKyTuAnh;
using MCGioiThieuHang;
using MCChayAnhThuong;
using Microsoft.Phone.Tasks;

namespace VTGGoldMiner
{
    public class DaoVang : Microsoft.Xna.Framework.Game
    {
        private GraphicsDeviceManager graphics;
        private SpriteBatch spriteBatch;
        public Random ngaunhien = new Random();
        private MGioiThieuHang gthgioithieu;
        private string phienbangame = "GoldMiner 1.0.0.8";
        public string[] gtktdaydu = new string[]
        {"!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "+", "=", "-", "0",
         "9", "8", "7", "6", "5", "4", "3", "2", "1", "Q", "W", "E", "É", "È", "Ẻ",
         "Ẽ", "Ẹ", "Ê", "Ế", "Ề", "Ể", "Ễ", "Ệ", "R", "T", "Y", "Ý", "Ỳ", "Ỷ", "Ỹ",
         "Ỵ", "U", "Ú", "Ù", "Ủ", "Ũ", "Ụ", "Ư", "Ứ", "Ừ", "Ử", "Ữ", "Ự", "I", "Í",
         "Ì", "Ỉ", "Ĩ", "Ị", "O", "Ó", "Ò", "Ỏ", "Õ", "Ọ", "Ô", "Ố", "Ồ", "Ổ", "Ỗ",
         "Ộ", "Ơ", "Ớ", "Ờ", "Ở", "Ỡ", "Ợ", "P", "A", "Á", "À", "Ả", "Ã", "Ạ", "Ă",
         "Ắ", "Ằ", "Ẳ", "Ẵ", "Ặ", "Â", "Ấ", "Ầ", "Ẩ", "Ẫ", "Ậ", "S", "D", "Đ", "F",
         "G", "H", "J", "K", "L", "Z", "X", "C", "V", "B", "N", "M", "q", "w", "e",
         "é", "è", "ẻ", "ẽ", "ẹ", "ê", "ế", "ề", "ể", "ễ", "ệ", "r", "t", "y", "ý",
         "ỳ", "ỷ", "ỹ", "ỵ", "u", "ú", "ù", "ủ", "ũ", "ụ", "ư", "ứ", "ừ", "ử", "ữ",
         "ự", "i", "í", "ì", "ỉ", "ĩ", "ị", "o", "ó", "ò", "ỏ", "õ", "ọ", "ô", "ố",
         "ồ", "ổ", "ỗ", "ộ", "ơ", "ớ", "ờ", "ở", "ỡ", "ợ", "p", "a", "á", "à", "ả",
         "ã", "ạ", "ă", "ắ", "ằ", "ẳ", "ẵ", "ặ", "â", "ấ", "ầ", "ẩ", "ẫ", "ậ", "s",
         "d", "đ", "f", "g", "h", "j", "k", "l", "z", "x", "c", "v", "b", "n", "m",
         "[", "]", "{", "}", ";", ":", "'", ",", ".", "/", "<", ">", "?", "|", " "};
        //khai bao bien trong game
        private float rongmanhinh, daimanhinh, tilerong, tiledai;
        private string bangquangcao = "rong";
        private int nhacquangcao = 1;//neu bang 0 thi moi lan thoat khong nhac lai nua
        private int solansudung = 0;//dem so lan su dung de nhac nguoi dung danh gia
        private int solandungdenhac = 5;//sau 5 lan dung dau tien thi se nhac danh gia
        private double maluucaidat = 0;
        private double diemkyluc = 500;
        private double diemsoluu = 500;//bien lay tam du lieu luu tru khi load
        private int sophaoluu = 0;//bien lay tam du lieu luu tru khi load
        private string tepluucaidat = "luucaidat.bmt", tepluutrochoi = "luutrochoi.bmt";
        private string ngonngu = "english";
        private string luachon = "rong";
        private string baotrang = "tranggioithieu";
        private int manchoi = 1, thoigianchoi = 60, chaytg = 0, diadiem = 1;
        private double muctieu = 0;
        private int phantrammuctieu = 50;//muc tieu ke tiep bang muc tieu cong (50 + manchoi) phan tram tong gia tri cua tat ca cac vat the man moi
        private int trangthaitamdung = 0;//bang 1 tuc la tam dung game;
        private int tienhoamayman = 0, tienphao = 0, tiendonghothoigian = 0, tiendaykeothan = 0, tiennuocruavang = 0, tiennuocruakimcuong = 0, tiensachsuutap = 0;
        private int hthoamayman, htphao, htdonghothoigian, htdaykeothan, htnuocruavang, htnuocruakimcuong, htsachsuutap;
        //hinh anh tren trang dau
        private HinhAnh hanendau, hatengame, hachoi, hadiemcao, hacaidat, hatrogiup, hathoat, hachapnhan, hakhongnhaclai, hachoimoi, haluuvathoat, hatieptucchoi;
        //hinh anh tren trang cai dat
        private HinhAnh hanencaidat, haamthanh, hathanhamthanh, hatroamthanh, hadanhgia;
        private HinhAnh hachutiengviet, hachuenglish, hadautich, hatieptuc, haquaylai, hatrogiupchoie, hatrogiupchoiv, haquangcaoa, haquangcaov;
        //hinh anh tren trang mua ban
        private HinhAnh haquaybanhang, hatencuahang, hahoamayman, hadonghothoigian, hadaykeothan, hasachsuutap, haphao, hanuocruavang, hanuocruakimcuong, haphaosanchoi, hathoatvaluu;
        private Texture2D anhcauhoithoai = null, anhthongtinvatpham = null, anhchuthongbao = null, anhdiemsonhanvat = null, anhsomanchoi = null;
        private string noidungthongbao = "null";
        private int tinhtrangmuaban = 0;//neu bang 0 thi khong the kich vao vat pham nua,bang 1 thi co the mua
        //hinh anh nen trong san choi
        private HinhAnh hamdbienca, hamddongbang, hamdrungnui, hamdsamac, hamdthaonguyen, haldbienca, halddongbang, haldrungnui, haldsamac, haldthaonguyen;
        //hinh anh bang thong bao
        private HinhAnh habangthongbao, hanenhoithoai, habangthucdon;
        private int chaythongbao = 0, chaychodoi = 0, chaykeoman = 0;
        //hinh anh trong san choi
        private int hienthithucdon = 0;
        private HinhAnh hathanhdiem, habangthongso, hadungtiep, habattatam, hadungchoi, hanensophao;
        private HinhAnh hadaquyg, hadaquyy, hadaquyb, hadaquyr;
        private NhanVat nvonglao;
        private int soluongvatthe;
        private VatThe[] mangvatthe;
        private VatThe vtngaunhien;
        private MouseState trochuothientai, trochuottruocdo;
        private SoundEffect amchon, amcanhbao, amantien, amgaptrung, amphongday, amkeoday, amphaono, ambomno, amhoanthanh, amthatbai, ammuctieu, ambosuutap;
        private float kichthuocam = 0.5f, amhientai = 0.5f;
        private CacHam dungham;//su dung cac ham
        //anh vat the va mang vi tri co the gap vao vat the
        private Texture2D[] vtcucvang1, vtcucvang2, vtcucvang3, vtcucda1, vtcucda2, vtcucda3, vtkimcuong, vttuimayman, vtthuocno, vtdaquyg, vtdaquyy, vtdaquyb, vtdaquyr;
        private Texture2D[] vtdaulau, vtxuongsuon, vtxuongcang, vtquantai, vtlongcocarong, vtlongcocaday, vtchaicocaday, vtlumia, vtchiecguoc, vtchiecgiay, vtchairong, vtcaitau, vthombimat, vttomchaynhanh, vttomvakimcuong, vtjerrydinhanh, vtdonalchaynhanh, vtdonalvakimcuong, vtdonaldicham, vtmickeychaynhanh, vtmickeyvakimcuong, vtmickeydicham;
        private Rectangle bocucvang1, bocucvang2, bocucvang3, bocucda1, bocucda2, bocucda3, bokimcuong, botuimayman, bothuocno, bodaquyg, bodaquyy, bodaquyb, bodaquyr;
        private Rectangle bodaulau, boxuongsuon, boxuongcang, boquantai, bolongcocarong, bolongcocaday, bochaicocaday, bolumia, bochiecguoc, bochiecgiay, bochairong, bocaitau, bohombimat, botomchaynhanh, botomvakimcuong, bojerrydinhanh, bodonalchaynhanh, bodonalvakimcuong, bodonaldicham, bomickeychaynhanh, bomickeyvakimcuong, bomickeydicham;
        //bien ngon ngu
        private string cauhoithoaita1 = "How can i help you?";
        private string cauhoithoaita2 = "What do you want to buy?";
        private string cauhoithoaita3 = "You should equip items!";
        private string cauhoithoaita4 = "Good luck!";
        private string cauhoithoaita5 = "Good day!";
        private string cauhoithoaita6 = "Goodbye!";
        private string cauhoithoaita7 = "You don't have enough money!";
        private string tenthongbaota1 = "HIGH SCORES";
        private string tenthongbaota2 = "INTENT";
        private string tenthongbaota3 = "COMPLETE";
        private string tenthongbaota4 = "FAILED";
        private string cauhoithoaitv1 = "Tôi có thể giúp gì cho bạn?";
        private string cauhoithoaitv2 = "Bạn cần trang bị những gì?";
        private string cauhoithoaitv3 = "Bạn nên trang bị các vật phẩm!";
        private string cauhoithoaitv4 = "Chúc may mắn!";
        private string cauhoithoaitv5 = "Một ngày tốt lành!";
        private string cauhoithoaitv6 = "Tạm biệt!";
        private string cauhoithoaitv7 = "Bạn không đủ tiền!";
        private string tenthongbaotv1 = "ĐIỂM KỶ LỤC";
        private string tenthongbaotv2 = "MỤC TIÊU";
        private string tenthongbaotv3 = "HOÀN THÀNH";
        private string tenthongbaotv4 = "THẤT BẠI";
        private Texture2D adiemtientrinh, adiemmanchoi, athoigianchoi, asophaono, achuphienban;
        private string scdiemtientrinh;
        private int scsophao = 0;
        //khai bao cac bo ky tu co the hien thi dong thoi va gia tri
        public int slbokytu = 12;//neu them cac bo ky tu chu thi them o day
        public MChuoiKyTuAnh[] bokytu;
        //cac bien gia tri nap cho bo ky tu tuong ung
        public Texture2D[] anhbkt0, anhbkt1, anhbkt2;
        public string[] giatribkt0, giatribkt1, giatribkt2;
        public int[] dorongbkt0, dorongbkt1, dorongbkt2;
        public Texture2D dauchambkt0, dauchambkt1, dauchambkt2;
        private int[] drbochunhoyellow = new int[] { 5, 17, 12, 10, 15, 9, 12, 8, 7, 7, 12, 11, 11, 7, 10, 10, 11, 10, 11, 11, 11, 10, 10, 7, 14, 18, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 12, 14, 14, 14, 14, 14, 14, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 5, 6, 6, 5, 9, 5, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 12, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 12, 13, 14, 11, 13, 12, 9, 13, 11, 12, 14, 13, 14, 12, 12, 14, 10, 15, 11, 11, 11, 11, 11, 11, 11, 12, 12, 11, 11, 11, 8, 7, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 5, 6, 6, 5, 8, 5, 11, 11, 11, 11, 11, 11, 11, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 12, 11, 11, 10, 10, 10, 10, 11, 8, 10, 10, 6, 10, 5, 10, 11, 10, 11, 11, 10, 14, 7, 7, 7, 7, 5, 5, 5, 5, 5, 8, 11, 11, 10, 1, 4 };
        private int[] drbochuthuongblack = new int[] { 4, 21, 13, 11, 17, 10, 14, 8, 6, 6, 14, 12, 12, 7, 11, 11, 11, 11, 11, 12, 12, 11, 12, 7, 16, 21, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 13, 16, 16, 16, 16, 16, 16, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 4, 6, 5, 5, 8, 4, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 14, 16, 12, 16, 13, 10, 14, 11, 13, 16, 15, 16, 13, 13, 16, 11, 17, 12, 12, 12, 12, 12, 12, 12, 13, 13, 12, 12, 12, 7, 6, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 3, 6, 5, 5, 9, 3, 12, 12, 12, 12, 12, 12, 12, 13, 13, 12, 12, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 13, 12, 12, 11, 11, 10, 11, 12, 8, 11, 10, 6, 10, 3, 11, 12, 11, 11, 11, 10, 16, 5, 5, 7, 7, 4, 4, 4, 4, 4, 8, 12, 12, 11, 1, 5 };
        private int[] drbochulongreen = new int[] { 9, 27, 22, 17, 29, 21, 24, 17, 13, 14, 21, 21, 20, 13, 18, 18, 19, 18, 19, 17, 19, 17, 17, 15, 23, 29, 18, 18, 18, 18, 18, 18, 18, 20, 20, 21, 18, 18, 21, 22, 21, 21, 21, 21, 21, 21, 20, 20, 20, 20, 20, 20, 24, 24, 24, 24, 24, 24, 14, 14, 14, 14, 16, 14, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 25, 25, 25, 25, 25, 25, 18, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 22, 22, 19, 21, 23, 18, 22, 20, 15, 20, 17, 19, 20, 21, 22, 19, 20, 23, 18, 24, 18, 18, 18, 18, 18, 18, 18, 20, 20, 20, 18, 18, 13, 15, 19, 19, 19, 19, 19, 19, 17, 17, 17, 17, 17, 17, 21, 21, 21, 21, 21, 21, 8, 11, 10, 9, 13, 9, 19, 19, 19, 19, 19, 19, 19, 21, 20, 20, 19, 19, 20, 20, 20, 20, 20, 20, 18, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 20, 19, 19, 17, 17, 16, 18, 20, 14, 18, 17, 13, 18, 8, 16, 18, 17, 19, 18, 17, 25, 13, 12, 16, 16, 11, 9, 8, 11, 8, 15, 20, 20, 16, 1, 8 };
        private MChayAnhThuong ifacebook, itwitter, iemail, idaovang, ivuaxocdia, iruntodeath;
        //chuong trinh chinh
        public DaoVang()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            graphics.IsFullScreen = true;
            TargetElapsedTime = TimeSpan.FromSeconds(0.04);
        }
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            dungham = new CacHam(GraphicsDevice);
            LayDuLieuLuu();
            amhientai = kichthuocam;
            if (solansudung < 9) solansudung++;
            //nap cac gia tri luc khoi dong game
            rongmanhinh = graphics.GraphicsDevice.Viewport.Width;
            daimanhinh = graphics.GraphicsDevice.Viewport.Height;
            tilerong = rongmanhinh / 640;
            tiledai = daimanhinh / 480;
            //nap du lieu gioi thieu hang
            Texture2D[] dsanhgt = new Texture2D[16];
            for (int i = 0; i < 16; i++) dsanhgt[i] = Content.Load<Texture2D>("HinhAnh/GioiThieuHang/HangSanXuat/" + (i + 1).ToString());
            gthgioithieu = new MGioiThieuHang(dsanhgt, Content.Load<Texture2D>("HinhAnh/GioiThieuHang/NenGioiThieu"), Content.Load<SoundEffect>("AmThanh/AmGioiThieu"), 640, 480, tilerong, tiledai);
        }
        protected override void UnloadContent()
        {
            base.UnloadContent();
        }
        protected override void Initialize()
        {
            base.Initialize();
        }
        protected override void Update(GameTime gameTime)
        {
            NapLaiDuLieu();
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                luachon = "rong";
                if (baotrang == "trangdau")
                {
                    if ((nhacquangcao == 1) & (solansudung >= solandungdenhac)) bangquangcao = "co";
                    else
                    {
                        LuuTruDuLieu(nhacquangcao);
                        this.Exit();
                    }
                }
                else if (baotrang == "trangdiemcao")
                {
                    chaychodoi = 0;
                    chaythongbao = 0;
                    habangthongbao.DichChuyen(174, chaythongbao - 190, tilerong, tiledai);
                    baotrang = "trangdau";
                }
                else if ((baotrang == "trangcaidat") | (baotrang == "trangtrogiup"))
                {
                    haquaylai.slchon = 0;
                    haquaylai.nhapnhay = 0;
                    bangquangcao = "rong";
                    baotrang = "trangdau";
                }
                else if (baotrang == "trangmuaban")
                {
                    haquaylai.slchon = 0;
                    haquaylai.nhapnhay = 0;
                    if (diemkyluc < nvonglao.diemso) diemkyluc = nvonglao.diemso;
                    baotrang = "trangdau";
                }
                else if (baotrang == "trangsanchoi")
                {
                    if (chaykeoman < 200) chaykeoman = 200;
                    else
                    {
                        if ((hienthithucdon == 1) & (hachoimoi.slchon != 1) & (haluuvathoat.slchon != 1) & (hatieptucchoi.slchon != 1)) hienthithucdon = 0;
                        else if ((hienthithucdon == 0) & (hadungchoi.slchon != 1)) hienthithucdon = 1;
                    }
                }
            }
            trochuothientai = GetMouseState();
            if (baotrang == "tranggioithieu")
            {
                if (gthgioithieu.ChayGioiThieu(2, 30, kichthuocam))
                {
                    NapCacBoKyTu();
                    NapAmThanh();
                    NapHinhAnh();
                    NapNgonNgu();
                    NapVatThe();
                    baotrang = "trangdau";
                    VeAnhChuPhienBan();
                    VeAnhDiemTienTrinh();
                    VeAnhSoPhaoNo();
                    scdiemtientrinh = nvonglao.diemso.ToString() + "/" + muctieu.ToString();
                    NapGameLienQuan();
                }
            }
            else if (baotrang == "trangdau")
            {
                if (bangquangcao == "rong")
                {
                    KichHoatGameLienQuan();
                    if ((hadiemcao.slchon != 1) & (hacaidat.slchon != 1) & (hatrogiup.slchon != 1) & (hathoat.slchon != 1))
                        hachoi.KichChonNhapNhay(trochuothientai, trochuottruocdo, 1, ref luachon, kichthuocam);
                    if ((hachoi.slchon != 1) & (hacaidat.slchon != 1) & (hatrogiup.slchon != 1) & (hathoat.slchon != 1))
                        hadiemcao.KichChonNhapNhay(trochuothientai, trochuottruocdo, 1, ref luachon, kichthuocam);
                    if ((hachoi.slchon != 1) & (hadiemcao.slchon != 1) & (hatrogiup.slchon != 1) & (hathoat.slchon != 1))
                        hacaidat.KichChonNhapNhay(trochuothientai, trochuottruocdo, 1, ref luachon, kichthuocam);
                    if ((hachoi.slchon != 1) & (hadiemcao.slchon != 1) & (hacaidat.slchon != 1) & (hathoat.slchon != 1))
                        hatrogiup.KichChonNhapNhay(trochuothientai, trochuottruocdo, 1, ref luachon, kichthuocam);
                    if ((hachoi.slchon != 1) & (hadiemcao.slchon != 1) & (hacaidat.slchon != 1) & (hatrogiup.slchon != 1))
                        hathoat.KichChonNhapNhay(trochuothientai, trochuottruocdo, 1, ref luachon, kichthuocam);
                    if (luachon == "nutchoi")
                    {
                        NapVatPham();
                        baotrang = "trangmuaban";
                    }
                    else if (luachon == "nutdiemcao")
                    {

                        if (ngonngu == "english") noidungthongbao = tenthongbaota1 + "|$" + diemkyluc.ToString();
                        else noidungthongbao = tenthongbaotv1 + "|$" + diemkyluc.ToString();
                        anhchuthongbao = bokytu[7].XuatAnhKyTu(noidungthongbao, 500, 166, 1, 1, 2, 2, Color.Transparent);
                        ammuctieu.Play(kichthuocam, 0, 0);
                        baotrang = "trangdiemcao";
                    }
                    else if (luachon == "nutcaidat") baotrang = "trangcaidat";
                    else if (luachon == "nuttrogiup") baotrang = "trangtrogiup";
                    else if (luachon == "nutthoat")
                    {
                        if ((nhacquangcao == 1) & (solansudung >= solandungdenhac)) bangquangcao = "co";
                        else
                        {
                            LuuTruDuLieu(nhacquangcao);
                            this.Exit();
                        }
                    }
                }
                else XuLyQuangCao();
                luachon = "rong";
            }
            else if (baotrang == "trangdiemcao")
            {
                if (chaythongbao < 190)
                {
                    chaythongbao = chaythongbao + 5;
                    habangthongbao.DichChuyen(174, chaythongbao - 190, tilerong, tiledai);
                }
                else chaychodoi++;
                if (chaychodoi == 50)
                {
                    chaychodoi = 0;
                    chaythongbao = 0;
                    habangthongbao.DichChuyen(174, chaythongbao - 190, tilerong, tiledai);
                    baotrang = "trangdau";
                }
            }
            else if (baotrang == "trangcaidat")
            {
                if (bangquangcao == "rong")
                {
                    haquaylai.KichChonNhapNhay(trochuothientai, trochuottruocdo, 1, ref luachon, kichthuocam);
                    hachuenglish.KichChonThuong(trochuothientai, trochuottruocdo, ref luachon, kichthuocam);
                    hachutiengviet.KichChonThuong(trochuothientai, trochuottruocdo, ref luachon, kichthuocam);
                    if (solansudung >= solandungdenhac) hadanhgia.KichChonThuong(trochuothientai, trochuottruocdo, ref luachon, kichthuocam);
                    if (trochuothientai.LeftButton == ButtonState.Pressed && trochuottruocdo.LeftButton == ButtonState.Released)
                    {
                        for (int i = 0; i <= 10; i++)
                        {
                            if (trochuothientai.X > (220 + 30 * i) * tilerong && trochuothientai.X < (220 + 30 * (i + 1)) * tilerong && trochuothientai.Y > 100 * tiledai && trochuothientai.Y < (100 + 63) * tiledai)
                            {
                                if (i < 10) kichthuocam = float.Parse("0." + i, CultureInfo.InvariantCulture.NumberFormat);
                                else kichthuocam = 1.0f;
                                amhientai = kichthuocam;
                                amchon.Play(kichthuocam, 0, 0);
                            }
                        }
                        hatroamthanh.DichChuyen(214 + (Convert.ToInt32(kichthuocam * 10) * 30), 133, tilerong, tiledai);
                    }
                    if (luachon == "anhchuenglish")
                    {
                        hadautich.DichChuyen(200, 196, tilerong, tiledai);
                        ngonngu = "english";
                        NapNgonNgu();
                    }
                    else if (luachon == "anhchutiengviet")
                    {
                        hadautich.DichChuyen(200, 266, tilerong, tiledai);
                        ngonngu = "tiengviet";
                        NapNgonNgu();
                    }
                    else if (luachon == "nutdanhgia") bangquangcao = "co";
                    else if (luachon == "anhquaylai") baotrang = "trangdau";
                }
                else XuLyQuangCao();
                luachon = "rong";
            }
            else if (baotrang == "trangtrogiup")
            {
                haquaylai.KichChonNhapNhay(trochuothientai, trochuottruocdo, 1, ref luachon, kichthuocam);
                if (luachon == "anhquaylai") baotrang = "trangdau";
                luachon = "rong";
            }
            else if (baotrang == "trangmuaban")
            {
                if (tinhtrangmuaban == 1)
                {
                    if (hthoamayman == 1) hahoamayman.KichChonNhapNhay(trochuothientai, trochuottruocdo, 2, ref luachon, kichthuocam);
                    if (htphao == 1) haphao.KichChonNhapNhay(trochuothientai, trochuottruocdo, 2, ref luachon, kichthuocam);
                    if (htdonghothoigian == 1) hadonghothoigian.KichChonNhapNhay(trochuothientai, trochuottruocdo, 2, ref luachon, kichthuocam);
                    if (htdaykeothan == 1) hadaykeothan.KichChonNhapNhay(trochuothientai, trochuottruocdo, 2, ref luachon, kichthuocam);
                    if (htnuocruavang == 1) hanuocruavang.KichChonNhapNhay(trochuothientai, trochuottruocdo, 2, ref luachon, kichthuocam);
                    if (htnuocruakimcuong == 1) hanuocruakimcuong.KichChonNhapNhay(trochuothientai, trochuottruocdo, 2, ref luachon, kichthuocam);
                    if (htsachsuutap == 1) hasachsuutap.KichChonNhapNhay(trochuothientai, trochuottruocdo, 2, ref luachon, kichthuocam);
                }
                if ((hahoamayman.slchon != 2) & (haphao.slchon != 2) & (hadonghothoigian.slchon != 2) & (hadaykeothan.slchon != 2) & (hanuocruavang.slchon != 2) & (hanuocruakimcuong.slchon != 2) & (hasachsuutap.slchon != 2))
                {
                    if (trochuothientai.LeftButton == ButtonState.Pressed && trochuottruocdo.LeftButton == ButtonState.Released)
                    {
                        if ((trochuothientai.X > 560 * tilerong && trochuothientai.X < (560 + 70) * tilerong && trochuothientai.Y > 400 * tiledai && trochuothientai.Y < (400 + 70) * tiledai) | (trochuothientai.X > 10 * tilerong && trochuothientai.X < (10 + 70) * tilerong && trochuothientai.Y > 400 * tiledai && trochuothientai.Y < (400 + 70) * tiledai))
                        {
                            if (tinhtrangmuaban == 1)
                            {
                                int caunoichao = Convert.ToInt32(ngaunhien.Next(1, 4));
                                if (ngonngu == "english")
                                {
                                    if (caunoichao == 1) anhcauhoithoai = bokytu[6].XuatAnhKyTu(cauhoithoaita4, 245, 66, 1, 1, 2, 2, Color.Transparent);
                                    else if (caunoichao == 2) anhcauhoithoai = bokytu[6].XuatAnhKyTu(cauhoithoaita5, 245, 66, 1, 1, 2, 2, Color.Transparent);
                                    else if (caunoichao == 3) anhcauhoithoai = bokytu[6].XuatAnhKyTu(cauhoithoaita6, 245, 66, 1, 1, 2, 2, Color.Transparent);
                                }
                                else
                                {
                                    if (caunoichao == 1) anhcauhoithoai = bokytu[6].XuatAnhKyTu(cauhoithoaitv4, 245, 66, 1, 1, 2, 2, Color.Transparent);
                                    else if (caunoichao == 2) anhcauhoithoai = bokytu[6].XuatAnhKyTu(cauhoithoaitv5, 245, 66, 1, 1, 2, 2, Color.Transparent);
                                    else if (caunoichao == 3) anhcauhoithoai = bokytu[6].XuatAnhKyTu(cauhoithoaitv6, 245, 66, 1, 1, 2, 2, Color.Transparent);
                                }
                            }
                            tinhtrangmuaban = 0;
                        }
                        else anhcauhoithoai = null;
                    }
                    if (hatieptuc.slchon != 1)
                        hathoatvaluu.KichChonNhapNhay(trochuothientai, trochuottruocdo, 1, ref luachon, kichthuocam);
                    if (haquaylai.slchon != 1)
                        hatieptuc.KichChonNhapNhay(trochuothientai, trochuottruocdo, 1, ref luachon, kichthuocam);
                } 
                if (ngonngu == "english")
                {
                    if ((hahoamayman.slchon == 1) | (hahoamayman.slchon == 2))
                        anhthongtinvatpham = bokytu[1].XuatAnhKyTu("Items: Lucky flowers ($" + tienhoamayman + ")|Effects: Increase the value of gift.", 450, 80, 1, 1, 1, 2, Color.Transparent);
                    else if ((haphao.slchon == 1) | (haphao.slchon == 2))
                        anhthongtinvatpham = bokytu[1].XuatAnhKyTu("Items: Firecrackers ($" + tienphao + ")|Effects: Destroy the pulling up object.", 450, 80, 1, 1, 1, 2, Color.Transparent);
                    else if ((hadonghothoigian.slchon == 1) | (hadonghothoigian.slchon == 2))
                        anhthongtinvatpham = bokytu[1].XuatAnhKyTu("Items: Clock time ($" + tiendonghothoigian + ")|Effects: Increase 15 seconds.", 450, 80, 1, 1, 1, 2, Color.Transparent);
                    else if ((hadaykeothan.slchon == 1) | (hadaykeothan.slchon == 2))
                        anhthongtinvatpham = bokytu[1].XuatAnhKyTu("Items: Zippers god ($" + tiendaykeothan + ")|Effects: Increase pulling up speed.", 450, 80, 1, 1, 1, 2, Color.Transparent);
                    else if ((hanuocruavang.slchon == 1) | (hanuocruavang.slchon == 2))
                        anhthongtinvatpham = bokytu[1].XuatAnhKyTu("Items: Gold washg ($" + tiennuocruavang + ")|Effects: Increase value of golds extra " + (70 + manchoi) + "%", 450, 80, 1, 1, 1, 2, Color.Transparent);
                    else if ((hanuocruakimcuong.slchon == 1) | (hanuocruakimcuong.slchon == 2))
                        anhthongtinvatpham = bokytu[1].XuatAnhKyTu("Items: Diamond washg ($" + tiennuocruakimcuong + ")|Effects: Increase value of diamonds extra " + (50 + manchoi) + "%", 450, 80, 1, 1, 1, 2, Color.Transparent);
                    else if ((hasachsuutap.slchon == 1) | (hasachsuutap.slchon == 2))
                        anhthongtinvatpham = bokytu[1].XuatAnhKyTu("Items: Book collection ($" + tiensachsuutap + ")|Effects: Increase value of stones and bones extra " + (100 + manchoi) + "%", 450, 80, 1, 1, 1, 2, Color.Transparent);
                    else anhthongtinvatpham = null;
                }
                else
                {
                    if ((hahoamayman.slchon == 1) | (hahoamayman.slchon == 2))
                        anhthongtinvatpham = bokytu[1].XuatAnhKyTu("Vật phẩm: Hoa may mắn ($" + tienhoamayman + ")|Tác dụng: Tăng giá trị túi quà và hòm bí mật.", 450, 80, 1, 1, 1, 2, Color.Transparent);
                    else if ((haphao.slchon == 1) | (haphao.slchon == 2))
                        anhthongtinvatpham = bokytu[1].XuatAnhKyTu("Vật phẩm: Pháo nổ ($" + tienphao + ")|Tác dụng: Phá hủy vật thể đang được kéo lên.", 450, 80, 1, 1, 1, 2, Color.Transparent);
                    else if ((hadonghothoigian.slchon == 1) | (hadonghothoigian.slchon == 2))
                        anhthongtinvatpham = bokytu[1].XuatAnhKyTu("Vật phẩm: Đồng hồ thời gian ($" + tiendonghothoigian + ")|Tác dụng: Tăng thêm 15 giây thời gian chơi.", 450, 80, 1, 1, 1, 2, Color.Transparent);
                    else if ((hadaykeothan.slchon == 1) | (hadaykeothan.slchon == 2))
                        anhthongtinvatpham = bokytu[1].XuatAnhKyTu("Vật phẩm: Dây kéo thần ($" + tiendaykeothan + ")|Tác dụng: Tăng tốc độ kéo vật thể.", 450, 80, 1, 1, 1, 2, Color.Transparent);
                    else if ((hanuocruavang.slchon == 1) | (hanuocruavang.slchon == 2))
                        anhthongtinvatpham = bokytu[1].XuatAnhKyTu("Vật phẩm: Nước rửa vàng ($" + tiennuocruavang + ")|Tác dụng: Tăng giá trị của vàng lên " + (70 + manchoi) + "%", 450, 80, 1, 1, 1, 2, Color.Transparent);
                    else if ((hanuocruakimcuong.slchon == 1) | (hanuocruakimcuong.slchon == 2))
                        anhthongtinvatpham = bokytu[1].XuatAnhKyTu("Vật phẩm: Nước rửa k.cương ($" + tiennuocruakimcuong + ")|Tác dụng: Tăng giá trị của kim cương lên " + (50 + manchoi) + "%", 450, 80, 1, 1, 1, 2, Color.Transparent);
                    else if ((hasachsuutap.slchon == 1) | (hasachsuutap.slchon == 2))
                        anhthongtinvatpham = bokytu[1].XuatAnhKyTu("Vật phẩm: Sách sưu tập ($" + tiensachsuutap + ")|Tác dụng: Tăng giá trị của đá và xương lên " + (100 + manchoi) + "%", 450, 80, 1, 1, 1, 2, Color.Transparent);
                    else anhthongtinvatpham = null;
                }
                if (luachon == "hoamayman")
                {
                    if (nvonglao.diemso >= tienhoamayman)
                    {
                        amgaptrung.Play(kichthuocam, 0, 0);
                        nvonglao.diemso = nvonglao.diemso - tienhoamayman;
                        hthoamayman = 2;
                        nvonglao.dhoamayman++;
                        anhdiemsonhanvat = bokytu[8].XuatAnhKyTu(nvonglao.diemso.ToString(), 0, 0, 1, 1, 1, 1, Color.Transparent);
                    }
                    else
                    {
                        amcanhbao.Play(kichthuocam, 0, 0);
                        if (ngonngu == "english") anhcauhoithoai = bokytu[6].XuatAnhKyTu(cauhoithoaita7, 245, 66, 1, 1, 2, 2, Color.Transparent);
                        else anhcauhoithoai = bokytu[6].XuatAnhKyTu(cauhoithoaitv7, 245, 66, 1, 1, 2, 2, Color.Transparent);
                    }
                }
                else if (luachon == "phao")
                {
                    if ((nvonglao.diemso >= tienphao) & (nvonglao.dphao < 99))
                    {
                        amgaptrung.Play(kichthuocam, 0, 0);
                        nvonglao.diemso = nvonglao.diemso - tienphao;
                        htphao = 2;
                        nvonglao.dphao++;
                        anhdiemsonhanvat = bokytu[8].XuatAnhKyTu(nvonglao.diemso.ToString(), 0, 0, 1, 1, 1, 1, Color.Transparent);
                        VeAnhSoPhaoNo();
                    }
                    else
                    {
                        amcanhbao.Play(kichthuocam, 0, 0);
                        if (ngonngu == "english") anhcauhoithoai = bokytu[6].XuatAnhKyTu(cauhoithoaita7, 245, 66, 1, 1, 2, 2, Color.Transparent);
                        else anhcauhoithoai = bokytu[6].XuatAnhKyTu(cauhoithoaitv7, 245, 66, 1, 1, 2, 2, Color.Transparent);
                    }
                }
                else if (luachon == "donghothoigian")
                {
                    if (nvonglao.diemso >= tiendonghothoigian)
                    {
                        amgaptrung.Play(kichthuocam, 0, 0);
                        nvonglao.diemso = nvonglao.diemso - tiendonghothoigian;
                        htdonghothoigian = 2;
                        nvonglao.ddonghothoigian++;
                        anhdiemsonhanvat = bokytu[8].XuatAnhKyTu(nvonglao.diemso.ToString(), 0, 0, 1, 1, 1, 1, Color.Transparent);
                    }
                    else
                    {
                        amcanhbao.Play(kichthuocam, 0, 0);
                        if (ngonngu == "english") anhcauhoithoai = bokytu[6].XuatAnhKyTu(cauhoithoaita7, 245, 66, 1, 1, 2, 2, Color.Transparent);
                        else anhcauhoithoai = bokytu[6].XuatAnhKyTu(cauhoithoaitv7, 245, 66, 1, 1, 2, 2, Color.Transparent);
                    }
                }
                else if (luachon == "daykeothan")
                {
                    if (nvonglao.diemso >= tiendaykeothan)
                    {
                        amgaptrung.Play(kichthuocam, 0, 0);
                        nvonglao.diemso = nvonglao.diemso - tiendaykeothan;
                        htdaykeothan = 2;
                        nvonglao.ddaykeothan++;
                        anhdiemsonhanvat = bokytu[8].XuatAnhKyTu(nvonglao.diemso.ToString(), 0, 0, 1, 1, 1, 1, Color.Transparent);
                    }
                    else
                    {
                        amcanhbao.Play(kichthuocam, 0, 0);
                        if (ngonngu == "english") anhcauhoithoai = bokytu[6].XuatAnhKyTu(cauhoithoaita7, 245, 66, 1, 1, 2, 2, Color.Transparent);
                        else anhcauhoithoai = bokytu[6].XuatAnhKyTu(cauhoithoaitv7, 245, 66, 1, 1, 2, 2, Color.Transparent);
                    }
                }
                else if (luachon == "nuocruavang")
                {
                    if (nvonglao.diemso >= tiennuocruavang)
                    {
                        amgaptrung.Play(kichthuocam, 0, 0);
                        nvonglao.diemso = nvonglao.diemso - tiennuocruavang;
                        htnuocruavang = 2;
                        nvonglao.dnuocruavang++;
                        anhdiemsonhanvat = bokytu[8].XuatAnhKyTu(nvonglao.diemso.ToString(), 0, 0, 1, 1, 1, 1, Color.Transparent);
                    }
                    else
                    {
                        amcanhbao.Play(kichthuocam, 0, 0);
                        if (ngonngu == "english") anhcauhoithoai = bokytu[6].XuatAnhKyTu(cauhoithoaita7, 245, 66, 1, 1, 2, 2, Color.Transparent);
                        else anhcauhoithoai = bokytu[6].XuatAnhKyTu(cauhoithoaitv7, 245, 66, 1, 1, 2, 2, Color.Transparent);
                    }
                }
                else if (luachon == "nuocruakimcuong")
                {
                    if (nvonglao.diemso >= tiennuocruakimcuong)
                    {
                        amgaptrung.Play(kichthuocam, 0, 0);
                        nvonglao.diemso = nvonglao.diemso - tiennuocruakimcuong;
                        htnuocruakimcuong = 2;
                        nvonglao.dnuocruakimcuong++;
                        anhdiemsonhanvat = bokytu[8].XuatAnhKyTu(nvonglao.diemso.ToString(), 0, 0, 1, 1, 1, 1, Color.Transparent);
                    }
                    else
                    {
                        amcanhbao.Play(kichthuocam, 0, 0);
                        if (ngonngu == "english") anhcauhoithoai = bokytu[6].XuatAnhKyTu(cauhoithoaita7, 245, 66, 1, 1, 2, 2, Color.Transparent);
                        else anhcauhoithoai = bokytu[6].XuatAnhKyTu(cauhoithoaitv7, 245, 66, 1, 1, 2, 2, Color.Transparent);
                    }
                }
                else if (luachon == "sachsuutap")
                {
                    if (nvonglao.diemso >= tiensachsuutap)
                    {
                        amgaptrung.Play(kichthuocam, 0, 0);
                        nvonglao.diemso = nvonglao.diemso - tiensachsuutap;
                        htsachsuutap = 2;
                        nvonglao.dsachsuutap++;
                        anhdiemsonhanvat = bokytu[8].XuatAnhKyTu(nvonglao.diemso.ToString(), 0, 0, 1, 1, 1, 1, Color.Transparent);
                    }
                    else
                    {
                        amcanhbao.Play(kichthuocam, 0, 0);
                        if (ngonngu == "english") anhcauhoithoai = bokytu[6].XuatAnhKyTu(cauhoithoaita7, 245, 66, 1, 1, 2, 2, Color.Transparent);
                        else anhcauhoithoai = bokytu[6].XuatAnhKyTu(cauhoithoaitv7, 245, 66, 1, 1, 2, 2, Color.Transparent);
                    }
                }
                else if (luachon == "anhthoatvaluu")
                {
                    if (diemkyluc < nvonglao.diemso) diemkyluc = nvonglao.diemso;
                    baotrang = "trangdau";
                }
                else if (luachon == "anhtieptuc")
                {
                    thoigianchoi = 60;
                    if (nvonglao.ddonghothoigian != 0) thoigianchoi = 75;
                    chaytg = 0;
                    NapManChoi();
                    if (ngonngu == "english") noidungthongbao = tenthongbaota2 + "|$" + muctieu.ToString();
                    else noidungthongbao = tenthongbaotv2 + "|$" + muctieu.ToString();
                    anhchuthongbao = bokytu[7].XuatAnhKyTu(noidungthongbao, 500, 166, 1, 1, 2, 2, Color.Transparent);
                    ammuctieu.Play(kichthuocam, 0, 0);
                    baotrang = "trangbaomuctieu";
                }
                luachon = "rong";
            }
            else if (baotrang == "trangsanchoi")
            {
                if (chaykeoman < 220)
                {
                    chaykeoman = chaykeoman + 5;
                    if (diadiem == 1)
                    {
                        hamdthaonguyen.DichChuyen(0, -chaykeoman, tilerong, tiledai);
                        haldthaonguyen.DichChuyen(0, -chaykeoman + 350, tilerong, tiledai);
                    }
                    else if (diadiem == 2)
                    {
                        hamdsamac.DichChuyen(0, -chaykeoman, tilerong, tiledai);
                        haldsamac.DichChuyen(0, -chaykeoman + 350, tilerong, tiledai);
                    }
                    else if (diadiem == 3)
                    {
                        hamddongbang.DichChuyen(0, -chaykeoman, tilerong, tiledai);
                        halddongbang.DichChuyen(0, -chaykeoman + 350, tilerong, tiledai);
                    }
                    else if (diadiem == 4)
                    {
                        hamdrungnui.DichChuyen(0, -chaykeoman, tilerong, tiledai);
                        haldrungnui.DichChuyen(0, -chaykeoman + 350, tilerong, tiledai);
                    }
                    else if (diadiem == 5)
                    {
                        hamdbienca.DichChuyen(0, -chaykeoman, tilerong, tiledai);
                        haldbienca.DichChuyen(0, -chaykeoman + 350, tilerong, tiledai);
                    }
                }
                else
                {
                    //tro choi chinh
                    if (hienthithucdon == 0)
                    {
                        habattatam.KichChuyenDoi(trochuothientai, trochuottruocdo, ref luachon, kichthuocam);
                        hadungtiep.KichChuyenDoi(trochuothientai, trochuottruocdo, ref luachon, kichthuocam);
                        hadungchoi.KichChonNhapNhay(trochuothientai, trochuottruocdo, 1, ref luachon, kichthuocam);
                        if (luachon == "battatam")
                        {
                            if (kichthuocam == 0.0f) kichthuocam = amhientai;
                            else kichthuocam = 0.0f;
                            hatroamthanh.DichChuyen(214 + (Convert.ToInt32(kichthuocam * 10) * 30), 133, tilerong, tiledai);
                        }
                        else if (luachon == "dungtiep")
                        {
                            if (trangthaitamdung == 0) trangthaitamdung = 1;
                            else trangthaitamdung = 0;
                        }
                        else if (luachon == "dungchoi")
                        {
                            hienthithucdon = 1;
                        }
                        if (trangthaitamdung == 0)
                        {
                            nvonglao.ThietLapDiChuyen(trochuothientai, trochuottruocdo, kichthuocam);
                            nvonglao.DiChuyen();
                            nvonglao.ThaDayKeo(trochuothientai, trochuottruocdo, ref thoigianchoi, manchoi, kichthuocam);
                            if (nvonglao.DangDoTim() == 1)
                            {
                                for (int i = 0; i < soluongvatthe; i++)
                                {
                                    if ((dungham.KiemTraGiaoHCN(nvonglao.vungmoc, mangvatthe[i].LanhThoVatThe())) & (mangvatthe[i].anhien == 1))
                                    {
                                        if (mangvatthe[i].toadoy + mangvatthe[i].chieudai > 180)
                                        {
                                            amgaptrung.Play(kichthuocam, 0, 0);
                                            nvonglao.DauMocCap("trung");
                                            nvonglao.KeoVatThe(mangvatthe[i], manchoi);
                                            break;
                                        }
                                    }
                                }
                            }
                            for (int i = 0; i < soluongvatthe; i++)
                            {
                                if ((mangvatthe[i].soanhthanhphan > 1) & (mangvatthe[i].anhien == 1))
                                {
                                    mangvatthe[i].HoatCanh();
                                }
                            }
                            if (nvonglao.dphao != 0)
                            {
                                haphaosanchoi.DichChuyen(nvonglao.toadoxnv - 10, 130, tilerong, tiledai);
                                hanensophao.DichChuyen(nvonglao.toadoxnv - 19, 155, tilerong, tiledai);
                                haphaosanchoi.KichChonNhapNhay(trochuothientai, trochuottruocdo, 1, ref luachon, kichthuocam);
                            }
                            if (luachon == "phaosanchoi")
                            {
                                nvonglao.SuDungPhaoNo();
                                VeAnhSoPhaoNo();
                            }
                            if (nvonglao.thuocnophat == 1)
                            {
                                Rectangle khuvucno = new Rectangle(nvonglao.tamthuocnox - nvonglao.bankinhno, nvonglao.tamthuocnoy - nvonglao.bankinhno, 2 * nvonglao.bankinhno, 2 * nvonglao.bankinhno);
                                for (int i = 0; i < soluongvatthe; i++)
                                {
                                    Rectangle cacvatthexet = new Rectangle(mangvatthe[i].toadox, mangvatthe[i].toadoy, mangvatthe[i].chieurong, mangvatthe[i].chieudai);
                                    if (dungham.KiemTraGiaoHCN(cacvatthexet, khuvucno))
                                    {
                                        mangvatthe[i].anhien = 2;
                                    }
                                }
                                ambomno.Play(kichthuocam, 0, 0);
                                nvonglao.thuocnophat = 0;
                            }
                            chaytg++;
                            if (chaytg == 25) { chaytg = 0; thoigianchoi--; VeAnhThoGianChoi(); }
                            if (thoigianchoi == 0)
                            {
                                haphaosanchoi.slchon = 0;
                                haphaosanchoi.nhapnhay = 0;
                                thoigianchoi = 60;
                                chaytg = 0;
                                if (nvonglao.diemso < muctieu)
                                {
                                    if (ngonngu == "english") noidungthongbao = tenthongbaota4 + "|" + nvonglao.diemso.ToString() + "/" + muctieu.ToString();
                                    else noidungthongbao = tenthongbaotv4 + "|" + nvonglao.diemso.ToString() + "/" + muctieu.ToString();
                                    anhchuthongbao = bokytu[7].XuatAnhKyTu(noidungthongbao, 500, 166, 1, 1, 2, 2, Color.Transparent);
                                    amthatbai.Play(kichthuocam, 0, 0);
                                    baotrang = "trangbaothua";
                                }
                                else
                                {
                                    if (ngonngu == "english") noidungthongbao = tenthongbaota3 + "|" + nvonglao.diemso.ToString() + "/" + muctieu.ToString();
                                    else noidungthongbao = tenthongbaotv3 + "|" + nvonglao.diemso.ToString() + "/" + muctieu.ToString();
                                    anhchuthongbao = bokytu[7].XuatAnhKyTu(noidungthongbao, 500, 166, 1, 1, 2, 2, Color.Transparent);
                                    amhoanthanh.Play(kichthuocam, 0, 0);
                                    baotrang = "trangbaothang";
                                }
                            }
                            if (scdiemtientrinh != nvonglao.diemso.ToString() + "/" + muctieu.ToString())
                            {
                                scdiemtientrinh = nvonglao.diemso.ToString() + "/" + muctieu.ToString();
                                VeAnhDiemTienTrinh();
                            }
                            if (scsophao != nvonglao.dphao)
                            {
                                VeAnhSoPhaoNo();
                                scsophao = nvonglao.dphao;
                            }
                        }
                    }
                    else//neu hien thi bang thuc don
                    {
                        hachoimoi.KichChonNhapNhay(trochuothientai, trochuottruocdo, 1, ref luachon, kichthuocam);
                        haluuvathoat.KichChonNhapNhay(trochuothientai, trochuottruocdo, 1, ref luachon, kichthuocam);
                        hatieptucchoi.KichChonNhapNhay(trochuothientai, trochuottruocdo, 1, ref luachon, kichthuocam);
                        if (luachon == "anhchoimoi")
                        {
                            hienthithucdon = 0;
                            LamMoiTroChoi();
                            baotrang = "trangdau";
                        }
                        else if (luachon == "anhluuvathoat")
                        {
                            hienthithucdon = 0;
                            LamMoiTroChoi();
                            LayDuLieuLuu();
                            baotrang = "trangdau";
                        }
                        else if (luachon == "anhtieptucchoi")
                        {
                            hienthithucdon = 0;
                        }
                    }
                }
                luachon = "rong";
            }
            else if (baotrang == "trangbaomuctieu")
            {
                if (chaythongbao < 190)
                {
                    chaythongbao = chaythongbao + 5;
                    habangthongbao.DichChuyen(174, chaythongbao - 190, tilerong, tiledai);
                }
                else chaychodoi++;
                if (chaychodoi == 50)
                {
                    //chuan bi san choi
                    chaykeoman = 0;
                    if (diadiem == 1)
                    {
                        hamdthaonguyen.DichChuyen(0, 0, tilerong, tiledai);
                        haldthaonguyen.DichChuyen(0, 350, tilerong, tiledai);
                    }
                    else if (diadiem == 2)
                    {
                        hamdsamac.DichChuyen(0, 0, tilerong, tiledai);
                        haldsamac.DichChuyen(0, 350, tilerong, tiledai);
                    }
                    else if (diadiem == 3)
                    {
                        hamddongbang.DichChuyen(0, 0, tilerong, tiledai);
                        halddongbang.DichChuyen(0, 350, tilerong, tiledai);
                    }
                    else if (diadiem == 4)
                    {
                        hamdrungnui.DichChuyen(0, 0, tilerong, tiledai);
                        haldrungnui.DichChuyen(0, 350, tilerong, tiledai);
                    }
                    else if (diadiem == 5)
                    {
                        hamdbienca.DichChuyen(0, 0, tilerong, tiledai);
                        haldbienca.DichChuyen(0, 350, tilerong, tiledai);
                    }
                    chaychodoi = 0;
                    chaythongbao = 0;
                    habangthongbao.DichChuyen(174, chaythongbao - 190, tilerong, tiledai);
                    VeAnhDiemManChoi();
                    baotrang = "trangsanchoi";
                }
            }
            else if (baotrang == "trangbaothang")
            {
                if (chaythongbao < 190)
                {
                    chaythongbao = chaythongbao + 5;
                    habangthongbao.DichChuyen(174, chaythongbao - 190, tilerong, tiledai);
                }
                else chaychodoi++;
                if (chaychodoi == 50)
                {
                    chaychodoi = 0;
                    chaythongbao = 0;
                    manchoi++;
                    nvonglao.TrangThaiDau();
                    habangthongbao.DichChuyen(174, chaythongbao - 190, tilerong, tiledai);
                    NapVatPham();
                    baotrang = "trangmuaban";
                }
            }
            else if (baotrang == "trangbaothua")
            {
                if (chaythongbao < 190)
                {
                    chaythongbao = chaythongbao + 5;
                    habangthongbao.DichChuyen(174, chaythongbao - 190, tilerong, tiledai);
                }
                else chaychodoi++;
                if (chaychodoi == 50)
                {
                    chaychodoi = 0;
                    chaythongbao = 0;
                    habangthongbao.DichChuyen(174, chaythongbao - 190, tilerong, tiledai);
                    LamMoiTroChoi();
                    LayDuLieuLuu();
                    baotrang = "trangdau";
                }
            }
            trochuottruocdo = trochuothientai;
            base.Update(gameTime);
        }
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);
            spriteBatch.Begin();
            if (baotrang == "tranggioithieu")
            {
                gthgioithieu.HienThiGioiThieu(spriteBatch);
            }
            else if (baotrang == "trangdau")
            {
                hanendau.HienThiThuong(spriteBatch);
                hatengame.HienThiThuong(spriteBatch);
                hachoi.HienThiNhapNhay(spriteBatch);
                hadiemcao.HienThiNhapNhay(spriteBatch);
                hacaidat.HienThiNhapNhay(spriteBatch);
                hatrogiup.HienThiNhapNhay(spriteBatch);
                hathoat.HienThiNhapNhay(spriteBatch);
                HienThiGameLienQuan(spriteBatch);
                VeBangQuangCao();
            }
            else if ((baotrang == "trangdiemcao") | (baotrang == "trangbaomuctieu") | (baotrang == "trangbaothang") | (baotrang == "trangbaothua"))
            {
                hanencaidat.HienThiThuong(spriteBatch);
                habangthongbao.HienThiThuong(spriteBatch);
                if (anhchuthongbao != null) spriteBatch.Draw(anhchuthongbao, dungham.BoHinhAnh(70, chaythongbao - 40, anhchuthongbao.Width, anhchuthongbao.Height, tilerong, tiledai), Color.White);
            }
            else if (baotrang == "trangcaidat")
            {
                hanencaidat.HienThiThuong(spriteBatch);
                haamthanh.HienThiThuong(spriteBatch);
                hathanhamthanh.HienThiThuong(spriteBatch);
                hatroamthanh.HienThiThuong(spriteBatch);
                hachuenglish.HienThiNhapNhay(spriteBatch);
                hachutiengviet.HienThiNhapNhay(spriteBatch);
                hadautich.HienThiThuong(spriteBatch);
                haquaylai.HienThiNhapNhay(spriteBatch);
                if (solansudung >= solandungdenhac) hadanhgia.HienThiThuong(spriteBatch);
                VeBangQuangCao();
            }
            else if (baotrang == "trangtrogiup")
            {
                hanencaidat.HienThiThuong(spriteBatch);
                if (ngonngu == "english") hatrogiupchoie.HienThiThuong(spriteBatch);
                else hatrogiupchoiv.HienThiThuong(spriteBatch);
                haquaylai.HienThiNhapNhay(spriteBatch);
                if (achuphienban != null) spriteBatch.Draw(achuphienban, dungham.BoHinhAnh(320, 430, 300, 30, tilerong, tiledai), Color.White);
            }
            else if (baotrang == "trangmuaban")
            {
                if (diadiem == 1) hamdthaonguyen.HienThiThuong(spriteBatch);
                else if (diadiem == 2) hamdsamac.HienThiThuong(spriteBatch);
                else if (diadiem == 3) hamddongbang.HienThiThuong(spriteBatch);
                else if (diadiem == 4) hamdrungnui.HienThiThuong(spriteBatch);
                else if (diadiem == 5) hamdbienca.HienThiThuong(spriteBatch);
                haquaybanhang.HienThiThuong(spriteBatch);
                hatencuahang.HienThiThuong(spriteBatch);
                if (anhdiemsonhanvat != null) spriteBatch.Draw(anhdiemsonhanvat, dungham.BoHinhAnh(38, 6, Convert.ToInt32(anhdiemsonhanvat.Width / 1.5), 36, tilerong, tiledai), Color.White);
                if (anhsomanchoi != null) spriteBatch.Draw(anhsomanchoi, dungham.BoHinhAnh(540, 21, Convert.ToInt32(anhsomanchoi.Width / 1.5), 36, tilerong, tiledai), Color.White);
                if (hthoamayman == 1) hahoamayman.HienThiNhapNhay(spriteBatch);
                if (htphao == 1) haphao.HienThiNhapNhay(spriteBatch);
                if (htdonghothoigian == 1) hadonghothoigian.HienThiNhapNhay(spriteBatch);
                if (htdaykeothan == 1) hadaykeothan.HienThiNhapNhay(spriteBatch);
                if (htnuocruavang == 1) hanuocruavang.HienThiNhapNhay(spriteBatch);
                if (htnuocruakimcuong == 1) hanuocruakimcuong.HienThiNhapNhay(spriteBatch);
                if (htsachsuutap == 1) hasachsuutap.HienThiNhapNhay(spriteBatch);
                hathoatvaluu.HienThiNhapNhay(spriteBatch);
                hatieptuc.HienThiNhapNhay(spriteBatch);
                if (anhthongtinvatpham != null) spriteBatch.Draw(anhthongtinvatpham, dungham.BoHinhAnh(95, 402, anhthongtinvatpham.Width, anhthongtinvatpham.Height, tilerong, tiledai), Color.White);
                if (anhcauhoithoai != null)
                {
                    hanenhoithoai.HienThiThuong(spriteBatch);
                    spriteBatch.Draw(anhcauhoithoai, dungham.BoHinhAnh(128, 96, anhcauhoithoai.Width, anhcauhoithoai.Height, tilerong, tiledai), Color.White);
                }
            }
            else if (baotrang == "trangsanchoi")
            {
                if (diadiem == 1)
                {
                    hamdthaonguyen.HienThiThuong(spriteBatch);
                    haldthaonguyen.HienThiThuong(spriteBatch);
                }
                else if (diadiem == 2)
                {
                    hamdsamac.HienThiThuong(spriteBatch);
                    haldsamac.HienThiThuong(spriteBatch);
                }
                else if (diadiem == 3)
                {
                    hamddongbang.HienThiThuong(spriteBatch);
                    halddongbang.HienThiThuong(spriteBatch);
                }
                else if (diadiem == 4)
                {
                    hamdrungnui.HienThiThuong(spriteBatch);
                    haldrungnui.HienThiThuong(spriteBatch);
                }
                else if (diadiem == 5)
                {
                    hamdbienca.HienThiThuong(spriteBatch);
                    haldbienca.HienThiThuong(spriteBatch);
                }
                if (chaykeoman >= 220)
                {
                    for (int i = 0; i < soluongvatthe; i++) mangvatthe[i].HienThi(spriteBatch);

                    dungham.VeDuongThang(spriteBatch, 10 * tiledai, Color.Black, new Vector2(63 * tilerong, 35 * tiledai), new Vector2(221 * tilerong, 35 * tiledai));
                    Color mauduongtien = Color.Lime;
                    double phantramdadat = nvonglao.diemso / muctieu;
                    if (phantramdadat >= 1)
                    {
                        phantramdadat = 1;
                        mauduongtien = Color.Gold;
                    }
                    int dodaidiem = Convert.ToInt32(phantramdadat * 157);
                    dungham.VeDuongThang(spriteBatch, 7 * tiledai, mauduongtien, new Vector2(64 * tilerong, 36 * tiledai), new Vector2((dodaidiem + 64) * tilerong, 36 * tiledai));
                    hathanhdiem.HienThiThuong(spriteBatch);

                    if (adiemmanchoi != null) spriteBatch.Draw(adiemmanchoi, dungham.BoHinhAnh(6, 30, 50, 30, tilerong, tiledai), Color.White);

                    if (adiemtientrinh != null) spriteBatch.Draw(adiemtientrinh, dungham.BoHinhAnh(64, 50, 155, 26, tilerong, tiledai), Color.White);

                    habangthongso.HienThiThuong(spriteBatch);
                    if (athoigianchoi != null) spriteBatch.Draw(athoigianchoi, dungham.BoHinhAnh(425, 32, 30, 30, tilerong, tiledai), Color.White);
                    habattatam.HienThiThuong(spriteBatch);
                    hadungtiep.HienThiThuong(spriteBatch);
                    hadungchoi.HienThiNhapNhay(spriteBatch);

                    if (nvonglao.daquyg != 0) hadaquyg.HienThiThuong(spriteBatch);
                    if (nvonglao.daquyy != 0) hadaquyy.HienThiThuong(spriteBatch);
                    if (nvonglao.daquyb != 0) hadaquyb.HienThiThuong(spriteBatch);
                    if (nvonglao.daquyr != 0) hadaquyr.HienThiThuong(spriteBatch);

                    if (nvonglao.dphao != 0)
                    {
                        haphaosanchoi.HienThiNhapNhay(spriteBatch);
                        hanensophao.HienThiThuong(spriteBatch);
                        if (asophaono != null) spriteBatch.Draw(asophaono, dungham.BoHinhAnh(nvonglao.toadoxnv - 21, 152, 30, 30, tilerong, tiledai), Color.White);
                    }

                    nvonglao.HienThi(spriteBatch);
                    if (hienthithucdon == 1)
                    {
                        habangthucdon.HienThiThuong(spriteBatch);
                        hachoimoi.HienThiNhapNhay(spriteBatch);
                        haluuvathoat.HienThiNhapNhay(spriteBatch);
                        hatieptucchoi.HienThiNhapNhay(spriteBatch);
                    }
                }
            }
            spriteBatch.End();
            base.Draw(gameTime);
        }
        protected void NapCacBoKyTu()
        {
            //thiet lap cac mang cua bo ky tu
            Array.Resize(ref bokytu, slbokytu);
            //bo chu phien ban tro choi
            NapBoKyTu(ref anhbkt0, ref dorongbkt0, ref giatribkt0, ref dauchambkt0, "HinhAnh/BKTTahomaS24Yellow", drbochunhoyellow, gtktdaydu, 219);
            bokytu[0] = new MChuoiKyTuAnh(GraphicsDevice, anhbkt0, dorongbkt0, giatribkt0, dauchambkt0,5);
            //bo chu thong tin vat pham
            bokytu[1] = new MChuoiKyTuAnh(GraphicsDevice, anhbkt0, dorongbkt0, giatribkt0, dauchambkt0, 5);
            //bo chu keo duoc qua may man
            bokytu[2] = new MChuoiKyTuAnh(GraphicsDevice, anhbkt0, dorongbkt0, giatribkt0, dauchambkt0, 5);
            //bo chu cap do man choi
            bokytu[3] = new MChuoiKyTuAnh(GraphicsDevice, anhbkt0, dorongbkt0, giatribkt0, dauchambkt0, 5);
            //bo chu dem thoi gian choi
            bokytu[4] = new MChuoiKyTuAnh(GraphicsDevice, anhbkt0, dorongbkt0, giatribkt0, dauchambkt0, 5);
            //bo chu dem so luong phao
            bokytu[5] = new MChuoiKyTuAnh(GraphicsDevice, anhbkt0, dorongbkt0, giatribkt0, dauchambkt0, 5);
            //bo chu doc thoai khi trong cua hang
            NapBoKyTu(ref anhbkt1, ref dorongbkt1, ref giatribkt1, ref dauchambkt1, "HinhAnh/BKTTahomaS30Black", drbochuthuongblack, gtktdaydu, 219);
            bokytu[6] = new MChuoiKyTuAnh(GraphicsDevice, anhbkt1, dorongbkt1, giatribkt1, dauchambkt1, 4);
            //bo chu thong bao diem cao, muc tieu, hoanh thanh, that bai
            NapBoKyTu(ref anhbkt2, ref dorongbkt2, ref giatribkt2, ref dauchambkt2, "HinhAnh/BKTTahomaS40Green", drbochulongreen, gtktdaydu, 219);
            bokytu[7] = new MChuoiKyTuAnh(GraphicsDevice, anhbkt2, dorongbkt2, giatribkt2, dauchambkt2, 8);
            //bo chu diem trong cua hang
            bokytu[8] = new MChuoiKyTuAnh(GraphicsDevice, anhbkt2, dorongbkt2, giatribkt2, dauchambkt2, 8);
            //bo chu cap do trong cua hang
            bokytu[9] = new MChuoiKyTuAnh(GraphicsDevice, anhbkt2, dorongbkt2, giatribkt2, dauchambkt2, 8);
            //bo chu diem tien trinh trong san choi
            bokytu[10] = new MChuoiKyTuAnh(GraphicsDevice, anhbkt2, dorongbkt2, giatribkt2, dauchambkt2, 8);
            //bo chu diem keo duoc vat the
            bokytu[11] = new MChuoiKyTuAnh(GraphicsDevice, anhbkt2, dorongbkt2, giatribkt2, dauchambkt2, 8);
        }
        protected void NapNgonNgu()
        {
            Texture2D chudaovang = Content.Load<Texture2D>("HinhAnh/HinhAnhChu/CDaoVang/1");
            Texture2D chuchoit = Content.Load<Texture2D>("HinhAnh/HinhAnhChu/CChoi/1");
            Texture2D chuchois = Content.Load<Texture2D>("HinhAnh/HinhAnhChu/CChoi/2");
            Texture2D chudiemcaot = Content.Load<Texture2D>("HinhAnh/HinhAnhChu/CDiemCao/1");
            Texture2D chudiemcaos = Content.Load<Texture2D>("HinhAnh/HinhAnhChu/CDiemCao/2");
            Texture2D chucaidatt = Content.Load<Texture2D>("HinhAnh/HinhAnhChu/CCaiDat/1");
            Texture2D chucaidats = Content.Load<Texture2D>("HinhAnh/HinhAnhChu/CCaiDat/2");
            Texture2D chutrogiupt = Content.Load<Texture2D>("HinhAnh/HinhAnhChu/CTroGiup/1");
            Texture2D chutrogiups = Content.Load<Texture2D>("HinhAnh/HinhAnhChu/CTroGiup/2");
            Texture2D chuthoatt = Content.Load<Texture2D>("HinhAnh/HinhAnhChu/CThoat/1");
            Texture2D chuthoats = Content.Load<Texture2D>("HinhAnh/HinhAnhChu/CThoat/2");
            Texture2D chuchapnhant = Content.Load<Texture2D>("HinhAnh/HinhAnhChu/CNutChon/1");
            Texture2D chuchapnhans = Content.Load<Texture2D>("HinhAnh/HinhAnhChu/CNutChon/2");
            Texture2D chukhongnhaclait = Content.Load<Texture2D>("HinhAnh/HinhAnhChu/CNutChon/5");
            Texture2D chukhongnhaclais = Content.Load<Texture2D>("HinhAnh/HinhAnhChu/CNutChon/6");
            Texture2D chudanhgia = Content.Load<Texture2D>("HinhAnh/HinhAnhChu/CDanhGia/1");
            Texture2D chucuahang = Content.Load<Texture2D>("HinhAnh/HinhAnhChu/CCuaHang/1");
            Texture2D thoatvaluu = Content.Load<Texture2D>("HinhAnh/HinhAnhChu/CThoatVaLuu/1");
            Texture2D choimoi = Content.Load<Texture2D>("HinhAnh/HinhAnhChu/CChoiMoi/1");
            Texture2D luuvathoat = Content.Load<Texture2D>("HinhAnh/HinhAnhChu/CLuuVaThoat/1");
            Texture2D tieptucchoi = Content.Load<Texture2D>("HinhAnh/HinhAnhChu/CTiepTuc/1");
            Texture2D anhdautich = Content.Load<Texture2D>("HinhAnh/DauTich");
            if (ngonngu != "english")
            {
                chudaovang = Content.Load<Texture2D>("HinhAnh/HinhAnhChu/CDaoVang/2");
                chuchoit = Content.Load<Texture2D>("HinhAnh/HinhAnhChu/CChoi/3");
                chuchois = Content.Load<Texture2D>("HinhAnh/HinhAnhChu/CChoi/4");
                chudiemcaot = Content.Load<Texture2D>("HinhAnh/HinhAnhChu/CDiemCao/3");
                chudiemcaos = Content.Load<Texture2D>("HinhAnh/HinhAnhChu/CDiemCao/4");
                chucaidatt = Content.Load<Texture2D>("HinhAnh/HinhAnhChu/CCaiDat/3");
                chucaidats = Content.Load<Texture2D>("HinhAnh/HinhAnhChu/CCaiDat/4");
                chutrogiupt = Content.Load<Texture2D>("HinhAnh/HinhAnhChu/CTroGiup/3");
                chutrogiups = Content.Load<Texture2D>("HinhAnh/HinhAnhChu/CTroGiup/4");
                chuthoatt = Content.Load<Texture2D>("HinhAnh/HinhAnhChu/CThoat/3");
                chuthoats = Content.Load<Texture2D>("HinhAnh/HinhAnhChu/CThoat/4");
                chuchapnhant = Content.Load<Texture2D>("HinhAnh/HinhAnhChu/CNutChon/3");
                chuchapnhans = Content.Load<Texture2D>("HinhAnh/HinhAnhChu/CNutChon/4");
                chukhongnhaclait = Content.Load<Texture2D>("HinhAnh/HinhAnhChu/CNutChon/7");
                chukhongnhaclais = Content.Load<Texture2D>("HinhAnh/HinhAnhChu/CNutChon/8");
                chudanhgia = Content.Load<Texture2D>("HinhAnh/HinhAnhChu/CDanhGia/2");
                chucuahang = Content.Load<Texture2D>("HinhAnh/HinhAnhChu/CCuaHang/2");
                thoatvaluu = Content.Load<Texture2D>("HinhAnh/HinhAnhChu/CThoatVaLuu/2");
                choimoi = Content.Load<Texture2D>("HinhAnh/HinhAnhChu/CChoiMoi/2");
                luuvathoat = Content.Load<Texture2D>("HinhAnh/HinhAnhChu/CLuuVaThoat/2");
                tieptucchoi = Content.Load<Texture2D>("HinhAnh/HinhAnhChu/CTiepTuc/2");
            } 
            Rectangle boanhchudaovang = dungham.BoHinhAnh(45, 34, 228, 67, tilerong, tiledai);
            hatengame = new HinhAnh("anhtengame", boanhchudaovang, chudaovang, chudaovang, null, null);
            Rectangle boanhchuchoi = dungham.BoHinhAnh(162, 180, 90, 62, tilerong, tiledai);
            hachoi = new HinhAnh("nutchoi", boanhchuchoi, chuchoit, chuchois, amchon, null);
            Rectangle boanhchudiemcao = dungham.BoHinhAnh(447, 125, 158, 43, tilerong, tiledai);
            hadiemcao = new HinhAnh("nutdiemcao", boanhchudiemcao, chudiemcaot, chudiemcaos, amchon, null);
            Rectangle boanhchucaidat = dungham.BoHinhAnh(472, 183, 121, 48, tilerong, tiledai);
            hacaidat = new HinhAnh("nutcaidat", boanhchucaidat, chucaidatt, chucaidats, amchon, null);
            Rectangle boanhchutrogiup = dungham.BoHinhAnh(462, 243, 115, 39, tilerong, tiledai);
            hatrogiup = new HinhAnh("nuttrogiup", boanhchutrogiup, chutrogiupt, chutrogiups, amchon, null);
            Rectangle boanhchuthoat = dungham.BoHinhAnh(473, 297, 83, 50, tilerong, tiledai);
            hathoat = new HinhAnh("nutthoat", boanhchuthoat, chuthoatt, chuthoats, amchon, null);
            Rectangle bochuchapnhan = dungham.BoHinhAnh(25, 390, 250, 40, tilerong, tiledai);
            hachapnhan = new HinhAnh("nutchapnhan", bochuchapnhan, chuchapnhant, chuchapnhans, amchon, null);
            Rectangle bochukhongnhaclai = dungham.BoHinhAnh(310, 390, 250, 40, tilerong, tiledai);
            hakhongnhaclai = new HinhAnh("nutkhongnhaclai", bochukhongnhaclai, chukhongnhaclait, chukhongnhaclais, amcanhbao, null);
            Rectangle boanhchudanhgia = dungham.BoHinhAnh(370, 410, 250, 40, tilerong, tiledai);
            hadanhgia = new HinhAnh("nutdanhgia", boanhchudanhgia, chudanhgia, chudanhgia, amchon, null);
            Rectangle boanhchucuahang = dungham.BoHinhAnh(232, 31, 180, 38, tilerong, tiledai);
            hatencuahang = new HinhAnh("anhchucuahang", boanhchucuahang, chucuahang, chucuahang, null, null);
            Rectangle boanhthoatvaluu = dungham.BoHinhAnh(10, 400, 70, 70, tilerong, tiledai);
            hathoatvaluu = new HinhAnh("anhthoatvaluu", boanhthoatvaluu, thoatvaluu, thoatvaluu, amchon, null);
            Rectangle boanhchoimoi = dungham.BoHinhAnh(220, 180, 200, 40, tilerong, tiledai);
            hachoimoi = new HinhAnh("anhchoimoi", boanhchoimoi, choimoi, choimoi, amchon, null);
            Rectangle boanhluuvathoat = dungham.BoHinhAnh(180, 220, 280, 40, tilerong, tiledai);
            haluuvathoat = new HinhAnh("anhluuvathoat", boanhluuvathoat, luuvathoat, luuvathoat, amchon, null);
            Rectangle boanhtieptucchoi = dungham.BoHinhAnh(220, 260, 200, 40, tilerong, tiledai);
            hatieptucchoi = new HinhAnh("anhtieptucchoi", boanhtieptucchoi, tieptucchoi, tieptucchoi, amchon, null);
            int vitritich = 196;
            if (ngonngu != "english") vitritich = 266;
            Rectangle boanhdautich = dungham.BoHinhAnh(200, vitritich, 67, 50, tilerong, tiledai);
            hadautich = new HinhAnh("anhdautich", boanhdautich, anhdautich, anhdautich, null, null);
            if (nvonglao != null) nvonglao.ngonnguht = ngonngu;
        }
        protected void NapHinhAnh()
        {
            Rectangle boanhnen = dungham.BoHinhAnh(0, 0, 640, 480, tilerong, tiledai);
            //nen trang dau
            Texture2D anhnendau = Content.Load<Texture2D>("HinhAnh/AnhNenDau");
            hanendau = new HinhAnh("anhnendau", boanhnen, anhnendau, anhnendau, null, null);
            //nen trang cai dat
            Texture2D anhnencaidat = Content.Load<Texture2D>("HinhAnh/NenCaiDat");
            hanencaidat = new HinhAnh("anhnencaidat", boanhnen, anhnencaidat, anhnencaidat, null, null);
            //anh tro giup
            Texture2D anhtrogiupchoie = Content.Load<Texture2D>("HinhAnh/TroGiupChoiE");
            hatrogiupchoie = new HinhAnh("anhtrogiupchoi", boanhnen, anhtrogiupchoie, anhtrogiupchoie, null, null);
            Texture2D anhtrogiupchoiv = Content.Load<Texture2D>("HinhAnh/TroGiupChoiV");
            hatrogiupchoiv = new HinhAnh("anhtrogiupchoi", boanhnen, anhtrogiupchoiv, anhtrogiupchoiv, null, null);
            //anh quang cao
            Texture2D anhquangcaoa = Content.Load<Texture2D>("HinhAnh/BTBQuangCaoA");
            haquangcaoa = new HinhAnh("anhquangcao", boanhnen, anhquangcaoa, anhquangcaoa, null, null);
            Texture2D anhquangcaov = Content.Load<Texture2D>("HinhAnh/BTBQuangCaoV");
            haquangcaov = new HinhAnh("anhquangcao", boanhnen, anhquangcaov, anhquangcaov, null, null);
            //nen trang mua ban
            Texture2D anhnenmuaban = Content.Load<Texture2D>("HinhAnh/QuayBanHang");
            haquaybanhang = new HinhAnh("anhnenmuaban", boanhnen, anhnenmuaban, anhnenmuaban, null, null);
            //hinh anh nen tren mat dat
            Rectangle boanhmd = dungham.BoHinhAnh(0, -120, 640, 400, tilerong, tiledai);
            Texture2D anhmdbienca = Content.Load<Texture2D>("HinhAnh/MDBienCa");
            hamdbienca = new HinhAnh("anhmdbienca", boanhmd, anhmdbienca, anhmdbienca, null, null);
            Texture2D anhmddongbang = Content.Load<Texture2D>("HinhAnh/MDDongBang");
            hamddongbang = new HinhAnh("anhmddongbang", boanhmd, anhmddongbang, anhmddongbang, null, null);
            Texture2D anhmdrungnui = Content.Load<Texture2D>("HinhAnh/MDRungNui");
            hamdrungnui = new HinhAnh("anhmdrungnui", boanhmd, anhmdrungnui, anhmdrungnui, null, null);
            Texture2D anhmdsamac = Content.Load<Texture2D>("HinhAnh/MDSaMac");
            hamdsamac = new HinhAnh("anhmdsamac", boanhmd, anhmdsamac, anhmdsamac, null, null);
            Texture2D anhmdthaonguyen = Content.Load<Texture2D>("HinhAnh/MDThaoNguyen");
            hamdthaonguyen = new HinhAnh("anhmdthaonguyen", boanhmd, anhmdthaonguyen, anhmdthaonguyen, null, null);
            //hinh anh nen trong long dat
            Rectangle boanhld = dungham.BoHinhAnh(0, 0, 640, 350, tilerong, tiledai);
            Texture2D anhldbienca = Content.Load<Texture2D>("HinhAnh/LDBienCa");
            haldbienca = new HinhAnh("anhldbienca", boanhld, anhldbienca, anhldbienca, null, null);
            Texture2D anhlddongbang = Content.Load<Texture2D>("HinhAnh/LDDongBang");
            halddongbang = new HinhAnh("anhlddongbang", boanhld, anhlddongbang, anhlddongbang, null, null);
            Texture2D anhldrungnui = Content.Load<Texture2D>("HinhAnh/LDRungNui");
            haldrungnui = new HinhAnh("anhldrungnui", boanhld, anhldrungnui, anhldrungnui, null, null);
            Texture2D anhldsamac = Content.Load<Texture2D>("HinhAnh/LDSaMac");
            haldsamac = new HinhAnh("anhldsamac", boanhld, anhldsamac, anhldsamac, null, null);
            Texture2D anhldthaonguyen = Content.Load<Texture2D>("HinhAnh/LDThaoNguyen");
            haldthaonguyen = new HinhAnh("anhldthaonguyen", boanhld, anhldthaonguyen, anhldthaonguyen, null, null);
            //vat pham trang bi
            Texture2D hoamaymant = Content.Load<Texture2D>("HinhAnh/HoaMayMan/1");
            Texture2D hoamaymans = Content.Load<Texture2D>("HinhAnh/HoaMayMan/2");
            Rectangle boanhoamayman = dungham.BoHinhAnh(35, 278, 65, 72, tilerong, tiledai);
            hahoamayman = new HinhAnh("hoamayman", boanhoamayman, hoamaymant, hoamaymans, amchon, null);
            Texture2D phaot = Content.Load<Texture2D>("HinhAnh/Phao/1");
            Texture2D phaos = Content.Load<Texture2D>("HinhAnh/Phao/2");
            Rectangle boanhphao = dungham.BoHinhAnh(110, 280, 25, 70, tilerong, tiledai);
            Rectangle boanhphaosanchoi = dungham.BoHinhAnh(260, 130, 18, 50, tilerong, tiledai);
            haphao = new HinhAnh("phao", boanhphao, phaot, phaos, amchon, null);
            haphaosanchoi = new HinhAnh("phaosanchoi", boanhphaosanchoi, phaot, phaos, amchon, amphaono);
            Texture2D donghothoigiant = Content.Load<Texture2D>("HinhAnh/DongHoThoiGian/1");
            Texture2D donghothoigians = Content.Load<Texture2D>("HinhAnh/DongHoThoiGian/2");
            Rectangle boanhdonghothoigian = dungham.BoHinhAnh(145, 286, 59, 64, tilerong, tiledai);
            hadonghothoigian = new HinhAnh("donghothoigian", boanhdonghothoigian, donghothoigiant, donghothoigians, amchon, null);
            Texture2D daykeothant = Content.Load<Texture2D>("HinhAnh/DayKeoThan/1");
            Texture2D daykeothans = Content.Load<Texture2D>("HinhAnh/DayKeoThan/2");
            Rectangle boanhdaykeothan = dungham.BoHinhAnh(214, 317, 82, 33, tilerong, tiledai);
            hadaykeothan = new HinhAnh("daykeothan", boanhdaykeothan, daykeothant, daykeothans, amchon, null);
            Texture2D nuocruavangt = Content.Load<Texture2D>("HinhAnh/NuocRuaVang/1");
            Texture2D nuocruavangs = Content.Load<Texture2D>("HinhAnh/NuocRuaVang/2");
            Rectangle boanhnuocruavang = dungham.BoHinhAnh(306, 281, 48, 69, tilerong, tiledai);
            hanuocruavang = new HinhAnh("nuocruavang", boanhnuocruavang, nuocruavangt, nuocruavangs, amchon, null);
            Texture2D nuocruakimcuongt = Content.Load<Texture2D>("HinhAnh/NuocRuaKimCuong/1");
            Texture2D nuocruakimcuongs = Content.Load<Texture2D>("HinhAnh/NuocRuaKimCuong/2");
            Rectangle boanhnuocruakimcuong = dungham.BoHinhAnh(364, 278, 56, 72, tilerong, tiledai);
            hanuocruakimcuong = new HinhAnh("nuocruakimcuong", boanhnuocruakimcuong, nuocruakimcuongt, nuocruakimcuongs, amchon, null);
            Texture2D sachsuutapt = Content.Load<Texture2D>("HinhAnh/SachSuuTap/1");
            Texture2D sachsuutaps = Content.Load<Texture2D>("HinhAnh/SachSuuTap/2");
            Rectangle boanhsachsuutap = dungham.BoHinhAnh(430, 283, 60, 67, tilerong, tiledai);
            hasachsuutap = new HinhAnh("sachsuutap", boanhsachsuutap, sachsuutapt, sachsuutaps, amchon, null);
            //nen hoi thoai
            Texture2D anhnenhoithoai = Content.Load<Texture2D>("HinhAnh/NenHoiThoai");
            Rectangle boanhnenhoithoai = dungham.BoHinhAnh(88, 71, 320, 146, tilerong, tiledai);
            hanenhoithoai = new HinhAnh("anhnenhoithoai", boanhnenhoithoai, anhnenhoithoai, anhnenhoithoai, null, null);
            //bang thong bao
            Texture2D anhbangthongbao = Content.Load<Texture2D>("HinhAnh/BangThongBao");
            Rectangle boanhbangthongbao = dungham.BoHinhAnh(174, -190, 292, 321, tilerong, tiledai);
            habangthongbao = new HinhAnh("anhbangthongbao", boanhbangthongbao, anhbangthongbao, anhbangthongbao, null, null);
            //bang thuc don
            Texture2D anhbangthucdon = Content.Load<Texture2D>("HinhAnh/BangThucDon");
            Rectangle boanhbangthucdon = dungham.BoHinhAnh(160, 120, 320, 240, tilerong, tiledai);
            habangthucdon = new HinhAnh("anhbangthucdon", boanhbangthucdon, anhbangthucdon, anhbangthucdon, null, null);
            //nhan vat chinh
            Texture2D[] anhnhanvatchinh = new Texture2D[11];
            for (int i = 0; i < 11; i++) anhnhanvatchinh[i] = Content.Load<Texture2D>("HinhAnh/NhanVatChinh/" + (i + 1).ToString());
            Texture2D[] anhdaumoc = new Texture2D[2];
            anhdaumoc[0] = Content.Load<Texture2D>("HinhAnh/DauMoc/1");
            anhdaumoc[1] = Content.Load<Texture2D>("HinhAnh/DauMoc/2");
            Texture2D[] anhnoboom = new Texture2D[5];
            for (int i = 0; i < 5; i++) anhnoboom[i] = Content.Load<Texture2D>("HinhAnh/NoBoom/" + (i + 1).ToString());
            nvonglao = new NhanVat(this, bokytu[11], bokytu[2], anhnhanvatchinh, anhdaumoc, anhnoboom, diemsoluu, 0, sophaoluu, 0, 0, 0, 0, 0, ngonngu, amphongday, amkeoday, amantien, ambosuutap, tilerong, tiledai);
            //hinh anh khac
            Texture2D anhamthanh = Content.Load<Texture2D>("HinhAnh/AnhAmThanh");
            Rectangle boanhamthanh = dungham.BoHinhAnh(90, 75, 128, 128, tilerong, tiledai);
            haamthanh = new HinhAnh("anhamthanh", boanhamthanh, anhamthanh, anhamthanh, null, null);
            Texture2D anhthanhamthanh = Content.Load<Texture2D>("HinhAnh/ThanhAmThanh");
            Rectangle boanhthanhamthanh = dungham.BoHinhAnh(220, 100, 326, 63, tilerong, tiledai);
            hathanhamthanh = new HinhAnh("anhthanhamthanh", boanhthanhamthanh, anhthanhamthanh, anhthanhamthanh, null, null);
            Texture2D anhtroamthanh = Content.Load<Texture2D>("HinhAnh/TroAmThanh");
            Rectangle boanhtroamthanh = dungham.BoHinhAnh(214, 133, 38, 44, tilerong, tiledai);
            hatroamthanh = new HinhAnh("anhtroamthanh", boanhtroamthanh, anhtroamthanh, anhtroamthanh, null, null);
            hatroamthanh.DichChuyen(214 + (Convert.ToInt32(kichthuocam * 10) * 30), 133, tilerong, tiledai);
            Texture2D anhthanhdiem = Content.Load<Texture2D>("HinhAnh/ThanhDiem");
            Rectangle boanhthanhdiem = dungham.BoHinhAnh(0, 0, 230, 82, tilerong, tiledai);
            hathanhdiem = new HinhAnh("anhthanhdiem", boanhthanhdiem, anhthanhdiem, anhthanhdiem, null, null);
            Texture2D anhbangthongso = Content.Load<Texture2D>("HinhAnh/BangThongSo");
            Rectangle boanhbangthongso = dungham.BoHinhAnh(410, 0, 230, 93, tilerong, tiledai);
            habangthongso = new HinhAnh("anhbangthongso", boanhbangthongso, anhbangthongso, anhbangthongso, null, null);
            //nap hinh anh phu tung khac
            Texture2D anhchuenglish = Content.Load<Texture2D>("HinhAnh/HinhaNhChu/CNgonNgu/1");
            Texture2D anhchutiengviet = Content.Load<Texture2D>("HinhAnh/HinhaNhChu/CNgonNgu/2");
            Rectangle boanhchuenglish = dungham.BoHinhAnh(267, 200, 173, 42, tilerong, tiledai);
            Rectangle bochutiengviet = dungham.BoHinhAnh(267, 270, 173, 42, tilerong, tiledai);
            hachuenglish = new HinhAnh("anhchuenglish", boanhchuenglish, anhchuenglish, anhchuenglish, amchon, null);
            hachutiengviet = new HinhAnh("anhchutiengviet", bochutiengviet, anhchutiengviet, anhchutiengviet, amchon, null);
            Texture2D anhquaylai = Content.Load<Texture2D>("HinhAnh/ChuyenTrang/1");
            Texture2D anhtieptuc = Content.Load<Texture2D>("HinhAnh/ChuyenTrang/2");
            Rectangle boanhquaylai = dungham.BoHinhAnh(10, 400, 70, 70, tilerong, tiledai);
            Rectangle boanhtieptuc = dungham.BoHinhAnh(560, 400, 70, 70, tilerong, tiledai);
            haquaylai = new HinhAnh("anhquaylai", boanhquaylai, anhquaylai, anhquaylai, amchon, null);
            hatieptuc = new HinhAnh("anhtieptuc", boanhtieptuc, anhtieptuc, anhtieptuc, amchon, null);
            Texture2D anhdaquyg = Content.Load<Texture2D>("HinhAnh/NgocTheoBo/1");
            Texture2D anhdaquyy = Content.Load<Texture2D>("HinhAnh/NgocTheoBo/2");
            Texture2D anhdaquyb = Content.Load<Texture2D>("HinhAnh/NgocTheoBo/3");
            Texture2D anhdaquyr = Content.Load<Texture2D>("HinhAnh/NgocTheoBo/4");
            Rectangle boanhdaquyg = dungham.BoHinhAnh(540, 75, 14, 15, tilerong, tiledai);
            Rectangle boanhdaquyy = dungham.BoHinhAnh(565, 75, 14, 15, tilerong, tiledai);
            Rectangle boanhdaquyb = dungham.BoHinhAnh(591, 75, 14, 15, tilerong, tiledai);
            Rectangle boanhdaquyr = dungham.BoHinhAnh(616, 75, 14, 15, tilerong, tiledai);
            hadaquyg = new HinhAnh("daquyg ", boanhdaquyg, anhdaquyg, anhdaquyg, null, null);
            hadaquyy = new HinhAnh("daquyy ", boanhdaquyy, anhdaquyy, anhdaquyy, null, null);
            hadaquyb = new HinhAnh("daquyb ", boanhdaquyb, anhdaquyb, anhdaquyb, null, null);
            hadaquyr = new HinhAnh("daquyr ", boanhdaquyr, anhdaquyr, anhdaquyr, null, null);
            NapTuyChinh();
        }
        protected void NapAmThanh()
        {
            amchon = Content.Load<SoundEffect>("AmThanh/AmChon");
            amantien = Content.Load<SoundEffect>("AmThanh/AmAnTien");
            amcanhbao = Content.Load<SoundEffect>("AmThanh/AmCanhBao");
            amgaptrung = Content.Load<SoundEffect>("AmThanh/AmGapTrung");
            amphongday = Content.Load<SoundEffect>("AmThanh/AmPhongDay");
            amkeoday = Content.Load<SoundEffect>("AmThanh/AmKeoDay");
            amphaono = Content.Load<SoundEffect>("AmThanh/AmPhaoNo");
            ambomno = Content.Load<SoundEffect>("AmThanh/AmBomNo");
            amhoanthanh = Content.Load<SoundEffect>("AmThanh/AmHoanThanh");
            amthatbai = Content.Load<SoundEffect>("AmThanh/AmThatBai");
            ammuctieu = Content.Load<SoundEffect>("AmThanh/AmMucTieu");
            ambosuutap = Content.Load<SoundEffect>("AmThanh/AmBoSuuTap");
        }
        protected void LamMoiTroChoi()
        {
            if (diemkyluc < nvonglao.diemso) diemkyluc = nvonglao.diemso;
            nvonglao.diemso = 500;
            nvonglao.dphao = 0;
            muctieu = 0;
            manchoi = 1;
            nvonglao.TrangThaiDau();
        }
        protected void NapNenMuaBan()
        {
            if (diadiem == 1) hamdthaonguyen.DichChuyen(0, -120, tilerong, tiledai);
            else if (diadiem == 2) hamdsamac.DichChuyen(0, -120, tilerong, tiledai);
            else if (diadiem == 3) hamddongbang.DichChuyen(0, -120, tilerong, tiledai);
            else if (diadiem == 4) hamdrungnui.DichChuyen(0, -120, tilerong, tiledai);
            else if (diadiem == 5) hamdbienca.DichChuyen(0, -120, tilerong, tiledai);
        }
        protected void NapVatPham()
        {
            LuuTruDuLieu(nhacquangcao);
            //cap nhat so diem choi
            anhdiemsonhanvat = bokytu[8].XuatAnhKyTu(nvonglao.diemso.ToString(), 0, 0, 1, 1, 1, 1, Color.Transparent);
            //cap nhat so man choi
            if (ngonngu == "english") anhsomanchoi = bokytu[9].XuatAnhKyTu("LV:" + manchoi.ToString(), 0, 0, 1, 1, 1, 1, Color.Transparent);
            else anhsomanchoi = bokytu[9].XuatAnhKyTu("CD:" + manchoi.ToString(), 0, 0, 1, 1, 1, 1, Color.Transparent);
            //ngau nhien xuat hien tu 1 den 2
            hthoamayman = Convert.ToInt32(ngaunhien.Next(1, 3));
            htphao = Convert.ToInt32(ngaunhien.Next(1, 3));
            htdonghothoigian = Convert.ToInt32(ngaunhien.Next(1, 3));
            htdaykeothan = Convert.ToInt32(ngaunhien.Next(1, 3));
            htnuocruavang = Convert.ToInt32(ngaunhien.Next(1, 3));
            htnuocruakimcuong = Convert.ToInt32(ngaunhien.Next(1, 3));
            htsachsuutap = Convert.ToInt32(ngaunhien.Next(1, 3));
            //ngau nhien gia tien tu tuy theo tung vat pham
            tienhoamayman = Convert.ToInt32(ngaunhien.Next(10, 500) + manchoi * 10);
            tienphao = Convert.ToInt32(ngaunhien.Next(10, 500) + manchoi * 10);
            tiendonghothoigian = Convert.ToInt32(ngaunhien.Next(100, 2000) + manchoi * 10);
            tiendaykeothan = Convert.ToInt32(ngaunhien.Next(500, 3000) + manchoi * 10);
            tiennuocruavang = Convert.ToInt32(ngaunhien.Next(10, 700) + manchoi * 10);
            tiennuocruakimcuong = Convert.ToInt32(ngaunhien.Next(10, 800) + manchoi * 10);
            tiensachsuutap = Convert.ToInt32(ngaunhien.Next(10, 500) + manchoi * 10);
            //ngau nhien dia diem tu 1 den 5
            diadiem = Convert.ToInt32(ngaunhien.Next(1, 6));
            NapNenMuaBan();
            //ngau nhien 3 cau chao hang
            int caunoichao = Convert.ToInt32(ngaunhien.Next(1, 4));
            if (ngonngu == "english")
            {
                if (caunoichao == 1) anhcauhoithoai = bokytu[6].XuatAnhKyTu(cauhoithoaita1, 245, 66, 1, 1, 2, 2, Color.Transparent);
                else if (caunoichao == 2) anhcauhoithoai = bokytu[6].XuatAnhKyTu(cauhoithoaita2, 245, 66, 1, 1, 2, 2, Color.Transparent);
                else if (caunoichao == 3) anhcauhoithoai = bokytu[6].XuatAnhKyTu(cauhoithoaita3, 245, 66, 1, 1, 2, 2, Color.Transparent);
            }
            else
            {
                if (caunoichao == 1) anhcauhoithoai = bokytu[6].XuatAnhKyTu(cauhoithoaitv1, 245, 66, 1, 1, 2, 2, Color.Transparent);
                else if (caunoichao == 2) anhcauhoithoai = bokytu[6].XuatAnhKyTu(cauhoithoaitv2, 245, 66, 1, 1, 2, 2, Color.Transparent);
                else if (caunoichao == 3) anhcauhoithoai = bokytu[6].XuatAnhKyTu(cauhoithoaitv3, 245, 66, 1, 1, 2, 2, Color.Transparent);
            }
            tinhtrangmuaban = 1;
            NapTuyChinh();
            if (nvonglao.dphao != 0)
            {
                haphaosanchoi.DichChuyen(nvonglao.toadoxnv - 10, 130, tilerong, tiledai);
                hanensophao.DichChuyen(nvonglao.toadoxnv - 19, 155, tilerong, tiledai);
            }
            VeAnhThoGianChoi();
        }
        protected void NapManChoi()
        {
            //ngau nhien so luong vat the tu 10 den 30
            soluongvatthe = Convert.ToInt32(ngaunhien.Next(10, 31));
            Array.Resize(ref mangvatthe, soluongvatthe);
            int dvatthe = 0; int solandatlaivt = 0;
            while (dvatthe < soluongvatthe)
            {
                NgauNhienVatThe();
                Rectangle khungvtm = new Rectangle(vtngaunhien.toadox, vtngaunhien.toadoy, vtngaunhien.chieurong, vtngaunhien.chieudai);
                //kiem tra vat the co bi trong cheo len nhau khong.
                int kt = 0;
                for (int i = 0; i < dvatthe; i++)
                {
                    Rectangle khungvtc = new Rectangle(mangvatthe[i].toadox, mangvatthe[i].toadoy, mangvatthe[i].chieurong, mangvatthe[i].chieudai);
                    if (dungham.KiemTraGiaoHCN(khungvtm, khungvtc))
                    {
                        kt = 1;
                        solandatlaivt++;
                        break;
                    }
                }
                //neu khong thi moi thiet dat
                if (kt == 0)
                {
                    mangvatthe[dvatthe] = vtngaunhien;
                    dvatthe++;
                    solandatlaivt = 0;
                }
                //neu tim lai vi tri moi qua 100 lan thi thoi 0 tim nua.
                if (solandatlaivt > 99)
                {
                    soluongvatthe = dvatthe;
                    Array.Resize(ref mangvatthe, soluongvatthe);
                }
            }
            VatThe vttg;
            for (int i = 0; i < soluongvatthe - 1; i++)
            {
                for (int j = i + 1; j < soluongvatthe; j++)
                {
                    if (mangvatthe[i].toadoy + mangvatthe[i].chieudai > mangvatthe[j].toadoy + mangvatthe[j].chieudai)
                    {
                        vttg = mangvatthe[i];
                        mangvatthe[i] = mangvatthe[j];
                        mangvatthe[j] = vttg;
                    }
                }

            }
            for (int i = 0; i < soluongvatthe; i++) muctieu = muctieu + Convert.ToInt32(mangvatthe[i].giatri * (phantrammuctieu + manchoi * 3) / 100);
        }
        protected void NapVatThe()
        {
            //cac the loai vat the duoc dinh nghia: vang,da,xuong,kimcuong,tuimayman,thuocno,daquyg,daquyy,daquyb,daquyr,hombimat
            vtcucvang1 = new Texture2D[1];
            vtcucvang1[0] = Content.Load<Texture2D>("HinhAnh/CucVang1");
            vtcucvang2 = new Texture2D[1];
            vtcucvang2[0] = Content.Load<Texture2D>("HinhAnh/CucVang2");
            vtcucvang3 = new Texture2D[1];
            vtcucvang3[0] = Content.Load<Texture2D>("HinhAnh/CucVang3");
            vtcucda1 = new Texture2D[1];
            vtcucda1[0] = Content.Load<Texture2D>("HinhAnh/CucDa1");
            vtcucda2 = new Texture2D[1];
            vtcucda2[0] = Content.Load<Texture2D>("HinhAnh/CucDa2");
            vtcucda3 = new Texture2D[1];
            vtcucda3[0] = Content.Load<Texture2D>("HinhAnh/CucDa3");
            vtkimcuong = new Texture2D[1];
            vtkimcuong[0] = Content.Load<Texture2D>("HinhAnh/KimCuong");
            vttuimayman = new Texture2D[1];
            vttuimayman[0] = Content.Load<Texture2D>("HinhAnh/TuiMayMan");
            vtthuocno = new Texture2D[1];
            vtthuocno[0] = Content.Load<Texture2D>("HinhAnh/ThuocNo");
            vtdaquyg = new Texture2D[1];
            vtdaquyg[0] = Content.Load<Texture2D>("HinhAnh/NgocTheoBo/1");
            vtdaquyy = new Texture2D[1];
            vtdaquyy[0] = Content.Load<Texture2D>("HinhAnh/NgocTheoBo/2");
            vtdaquyb = new Texture2D[1];
            vtdaquyb[0] = Content.Load<Texture2D>("HinhAnh/NgocTheoBo/3");
            vtdaquyr = new Texture2D[1];
            vtdaquyr[0] = Content.Load<Texture2D>("HinhAnh/NgocTheoBo/4");
            vtdaulau = new Texture2D[1];
            vtdaulau[0] = Content.Load<Texture2D>("HinhAnh/DauLau");
            vtxuongsuon = new Texture2D[1];
            vtxuongsuon[0] = Content.Load<Texture2D>("HinhAnh/XuongSuon");
            vtxuongcang = new Texture2D[1];
            vtxuongcang[0] = Content.Load<Texture2D>("HinhAnh/XuongCang");
            vtquantai = new Texture2D[1];
            vtquantai[0] = Content.Load<Texture2D>("HinhAnh/QuanTai");
            vtlongcocarong = new Texture2D[1];
            vtlongcocarong[0] = Content.Load<Texture2D>("HinhAnh/LongCocaRong");
            vtlongcocaday = new Texture2D[1];
            vtlongcocaday[0] = Content.Load<Texture2D>("HinhAnh/LongCocaDay");
            vtchaicocaday = new Texture2D[1];
            vtchaicocaday[0] = Content.Load<Texture2D>("HinhAnh/ChaiCocaDay");
            vtlumia = new Texture2D[1];
            vtlumia[0] = Content.Load<Texture2D>("HinhAnh/Lumia");
            vtchiecguoc = new Texture2D[1];
            vtchiecguoc[0] = Content.Load<Texture2D>("HinhAnh/ChiecGuoc");
            vtchiecgiay = new Texture2D[1];
            vtchiecgiay[0] = Content.Load<Texture2D>("HinhAnh/ChiecGiay");
            vtchairong = new Texture2D[1];
            vtchairong[0] = Content.Load<Texture2D>("HinhAnh/ChaiRong");
            vtcaitau = new Texture2D[1];
            vtcaitau[0] = Content.Load<Texture2D>("HinhAnh/CaiTau");
            vthombimat = new Texture2D[1];
            vthombimat[0] = Content.Load<Texture2D>("HinhAnh/HomBiMat");
            vttomchaynhanh = new Texture2D[14];
            vttomvakimcuong = new Texture2D[14];
            for (int i = 0; i < 14; i++)
            {
                vttomchaynhanh[i] = Content.Load<Texture2D>("HinhAnh/TomChayNhanh/" + (i + 1).ToString());
                vttomvakimcuong[i] = Content.Load<Texture2D>("HinhAnh/TomVaKimCuong/" + (i + 1).ToString());
            }
            vtjerrydinhanh = new Texture2D[16];
            vtdonalchaynhanh = new Texture2D[16];
            vtdonalvakimcuong = new Texture2D[16];
            vtdonaldicham = new Texture2D[16];
            vtmickeychaynhanh = new Texture2D[16];
            vtmickeyvakimcuong = new Texture2D[16];
            vtmickeydicham = new Texture2D[16];
            for (int i = 0; i < 16; i++)
            {
                vtjerrydinhanh[i] = Content.Load<Texture2D>("HinhAnh/JerryDiNhanh/" + (i + 1).ToString());
                vtdonalchaynhanh[i] = Content.Load<Texture2D>("HinhAnh/DonalChayNhanh/" + (i + 1).ToString());
                vtdonalvakimcuong[i] = Content.Load<Texture2D>("HinhAnh/DonalVaKimCuong/" + (i + 1).ToString());
                vtdonaldicham[i] = Content.Load<Texture2D>("HinhAnh/DonalDiCham/" + (i + 1).ToString());
                vtmickeychaynhanh[i] = Content.Load<Texture2D>("HinhAnh/MickeyChayNhanh/" + (i + 1).ToString());
                vtmickeyvakimcuong[i] = Content.Load<Texture2D>("HinhAnh/MickeyVaKimCuong/" + (i + 1).ToString());
                vtmickeydicham[i] = Content.Load<Texture2D>("HinhAnh/MickeyDiCham/" + (i + 1).ToString());
            }
            bocucvang1 = new Rectangle(0, 0, vtcucvang1[0].Width, vtcucvang1[0].Height);
            bocucvang2 = new Rectangle(0, 0, vtcucvang2[0].Width, vtcucvang2[0].Height);
            bocucvang3 = new Rectangle(0, 0, vtcucvang3[0].Width, vtcucvang3[0].Height);
            bocucda1 = new Rectangle(0, 0, vtcucda1[0].Width, vtcucda1[0].Height);
            bocucda2 = new Rectangle(0, 0, vtcucda2[0].Width, vtcucda2[0].Height);
            bocucda3 = new Rectangle(0, 0, vtcucda3[0].Width, vtcucda3[0].Height);
            bokimcuong = new Rectangle(0, 0, vtkimcuong[0].Width, vtkimcuong[0].Height);
            botuimayman = new Rectangle(0, 0, vttuimayman[0].Width, vttuimayman[0].Height);
            bothuocno = new Rectangle(0, 0, vtthuocno[0].Width, vtthuocno[0].Height);
            bodaquyb = new Rectangle(0, 0, vtdaquyb[0].Width, vtdaquyb[0].Height);
            bodaquyr = new Rectangle(0, 0, vtdaquyr[0].Width, vtdaquyr[0].Height);
            bodaquyy = new Rectangle(0, 0, vtdaquyy[0].Width, vtdaquyy[0].Height);
            bodaquyg = new Rectangle(0, 0, vtdaquyg[0].Width, vtdaquyg[0].Height);
            bodaulau = new Rectangle(0, 0, vtdaulau[0].Width, vtdaulau[0].Height);
            boxuongsuon = new Rectangle(0, 0, vtxuongsuon[0].Width, vtxuongsuon[0].Height);
            boxuongcang = new Rectangle(0, 0, vtxuongcang[0].Width, vtxuongcang[0].Height);
            boquantai = new Rectangle(0, 0, vtquantai[0].Width, vtquantai[0].Height);
            bolongcocarong = new Rectangle(0, 0, vtlongcocarong[0].Width, vtlongcocarong[0].Height);
            bolongcocaday = new Rectangle(0, 0, vtlongcocaday[0].Width, vtlongcocaday[0].Height);
            bochaicocaday = new Rectangle(0, 0, vtchaicocaday[0].Width, vtchaicocaday[0].Height);
            bolumia = new Rectangle(0, 0, vtlumia[0].Width, vtlumia[0].Height);
            bochiecguoc = new Rectangle(0, 0, vtchiecguoc[0].Width, vtchiecguoc[0].Height);
            bochiecgiay = new Rectangle(0, 0, vtchiecgiay[0].Width, vtchiecgiay[0].Height);
            bochairong = new Rectangle(0, 0, vtchairong[0].Width, vtchairong[0].Height);
            bocaitau = new Rectangle(0, 0, vtcaitau[0].Width, vtcaitau[0].Height);
            bohombimat = new Rectangle(0, 0, vthombimat[0].Width, vthombimat[0].Height);
            botomchaynhanh = new Rectangle(0, 0, vttomchaynhanh[0].Width, vttomchaynhanh[0].Height);
            botomvakimcuong = new Rectangle(0, 0, vttomvakimcuong[0].Width, vttomvakimcuong[0].Height);
            bojerrydinhanh = new Rectangle(0, 0, vtjerrydinhanh[0].Width, vtjerrydinhanh[0].Height);
            bodonalchaynhanh = new Rectangle(0, 0, vtdonalchaynhanh[0].Width, vtdonalchaynhanh[0].Height);
            bodonaldicham = new Rectangle(0, 0, vtdonaldicham[0].Width, vtdonaldicham[0].Height);
            bodonalvakimcuong = new Rectangle(0, 0, vtdonalvakimcuong[0].Width, vtdonalvakimcuong[0].Height);
            bomickeychaynhanh = new Rectangle(0, 0, vtmickeychaynhanh[0].Width, vtmickeychaynhanh[0].Height);
            bomickeydicham = new Rectangle(0, 0, vtmickeydicham[0].Width, vtmickeydicham[0].Height);
            bomickeyvakimcuong = new Rectangle(0, 0, vtmickeyvakimcuong[0].Width, vtmickeyvakimcuong[0].Height);
        }
        protected void NgauNhienVatThe()
        {
            //ngau nhien lon nhat la 35 vat the
            int giasongaunhien = manchoi;
            if (manchoi > 17) giasongaunhien = 17;
            int kieuvatthe = Convert.ToInt32(ngaunhien.Next(1, 2 + giasongaunhien * 2));
            if (kieuvatthe == 1)
            {
                bocucvang1.X = Convert.ToInt32(ngaunhien.Next(0, 640 - bocucvang1.Width));
                bocucvang1.Y = Convert.ToInt32(ngaunhien.Next(200, 480 - bocucvang1.Height));
                vtngaunhien = new VatThe(this, vtcucvang1, 0, new Vector2(1, 7), "cucvang", "vang", bocucvang1, 1, 500, 6f, new Vector2(52, 17), tilerong, tiledai);
            }
            else if (kieuvatthe == 2)
            {
                bocucvang2.X = Convert.ToInt32(ngaunhien.Next(0, 640 - bocucvang2.Width));
                bocucvang2.Y = Convert.ToInt32(ngaunhien.Next(200, 480 - bocucvang2.Height));
                vtngaunhien = new VatThe(this, vtcucvang2, 0, new Vector2(1, 7), "cucvang", "vang", bocucvang2, 1, 250, 5f, new Vector2(36, 11), tilerong, tiledai);
            }
            else if (kieuvatthe == 3)
            {
                bocucvang3.X = Convert.ToInt32(ngaunhien.Next(0, 640 - bocucvang3.Width));
                bocucvang3.Y = Convert.ToInt32(ngaunhien.Next(200, 480 - bocucvang3.Height));
                vtngaunhien = new VatThe(this, vtcucvang3, 0, new Vector2(1, 7), "cucvang", "vang", bocucvang3, 1, 150, 4f, new Vector2(27, 9), tilerong, tiledai);
            }
            else if (kieuvatthe == 4)
            {
                bocucda1.X = Convert.ToInt32(ngaunhien.Next(0, 640 - bocucda1.Width));
                bocucda1.Y = Convert.ToInt32(ngaunhien.Next(200, 480 - bocucda1.Height));
                vtngaunhien = new VatThe(this, vtcucda1, 0, new Vector2(1, 7), "cucda", "da", bocucda1, 1, 50, 6.1f, new Vector2(39, 9), tilerong, tiledai);
            }
            else if (kieuvatthe == 5)
            {
                bocucda2.X = Convert.ToInt32(ngaunhien.Next(0, 640 - bocucda2.Width));
                bocucda2.Y = Convert.ToInt32(ngaunhien.Next(200, 480 - bocucda2.Height));
                vtngaunhien = new VatThe(this, vtcucda2, 0, new Vector2(1, 7), "cucda", "da", bocucda2, 1, 45, 5.8f, new Vector2(31, 8), tilerong, tiledai);
            }
            else if (kieuvatthe == 6)
            {
                bocucda3.X = Convert.ToInt32(ngaunhien.Next(0, 640 - bocucda3.Width));
                bocucda3.Y = Convert.ToInt32(ngaunhien.Next(200, 480 - bocucda3.Height));
                vtngaunhien = new VatThe(this, vtcucda3, 0, new Vector2(1, 7), "cucda", "da", bocucda3, 1, 25, 5f, new Vector2(23, 7), tilerong, tiledai);
            }
            else if (kieuvatthe == 7)
            {
                bokimcuong.X = Convert.ToInt32(ngaunhien.Next(0, 640 - bokimcuong.Width));
                bokimcuong.Y = Convert.ToInt32(ngaunhien.Next(200, 480 - bokimcuong.Height));
                vtngaunhien = new VatThe(this, vtkimcuong, 0, new Vector2(1, 7), "kimcuong", "kimcuong", bokimcuong, 1, 600, 1f, new Vector2(12, 5), tilerong, tiledai);
            }
            else if (kieuvatthe == 8)
            {
                bodaulau.X = Convert.ToInt32(ngaunhien.Next(0, 640 - bodaulau.Width));
                bodaulau.Y = Convert.ToInt32(ngaunhien.Next(200, 480 - bodaulau.Height));
                vtngaunhien = new VatThe(this, vtdaulau, 0, new Vector2(1, 7), "daulau", "xuong", bodaulau, 1, 45, 3f, new Vector2(20, 6), tilerong, tiledai);
            }
            else if (kieuvatthe == 9)
            {
                boxuongsuon.X = Convert.ToInt32(ngaunhien.Next(0, 640 - boxuongsuon.Width));
                boxuongsuon.Y = Convert.ToInt32(ngaunhien.Next(200, 480 - boxuongsuon.Height));
                vtngaunhien = new VatThe(this, vtxuongsuon, 0, new Vector2(1, 7), "xuongsuon", "xuong", boxuongsuon, 1, 40, 3f, new Vector2(17, 8), tilerong, tiledai);
            }
            else if (kieuvatthe == 10)
            {
                boxuongcang.X = Convert.ToInt32(ngaunhien.Next(0, 640 - boxuongcang.Width));
                boxuongcang.Y = Convert.ToInt32(ngaunhien.Next(200, 480 - boxuongcang.Height));
                vtngaunhien = new VatThe(this, vtxuongcang, 0, new Vector2(1, 7), "xuongcang", "xuong", boxuongcang, 1, 35, 3f, new Vector2(18, 15), tilerong, tiledai);
            }
            else if (kieuvatthe == 11)
            {
                bodaquyg.X = Convert.ToInt32(ngaunhien.Next(0, 640 - bodaquyg.Width));
                bodaquyg.Y = Convert.ToInt32(ngaunhien.Next(200, 480 - bodaquyg.Height));
                vtngaunhien = new VatThe(this, vtdaquyg, 0, new Vector2(1, 7), "daquyg", "daquyg", bodaquyg, 1, 150, 1f, new Vector2(7, 5), tilerong, tiledai);
            }
            else if (kieuvatthe == 12)
            {
                bodaquyy.X = Convert.ToInt32(ngaunhien.Next(0, 640 - bodaquyy.Width));
                bodaquyy.Y = Convert.ToInt32(ngaunhien.Next(200, 480 - bodaquyy.Height));
                vtngaunhien = new VatThe(this, vtdaquyy, 0, new Vector2(1, 7), "daquyy", "daquyy", bodaquyy, 1, 150, 1f, new Vector2(7, 5), tilerong, tiledai);
            }
            else if (kieuvatthe == 13)
            {
                bodaquyb.X = Convert.ToInt32(ngaunhien.Next(0, 640 - bodaquyb.Width));
                bodaquyb.Y = Convert.ToInt32(ngaunhien.Next(200, 480 - bodaquyb.Height));
                vtngaunhien = new VatThe(this, vtdaquyb, 0, new Vector2(1, 7), "daquyb", "daquyb", bodaquyb, 1, 150, 1f, new Vector2(7, 5), tilerong, tiledai);
            }
            else if (kieuvatthe == 14)
            {
                bodaquyr.X = Convert.ToInt32(ngaunhien.Next(0, 640 - bodaquyr.Width));
                bodaquyr.Y = Convert.ToInt32(ngaunhien.Next(200, 480 - bodaquyr.Height));
                vtngaunhien = new VatThe(this, vtdaquyr, 0, new Vector2(1, 7), "daquyr", "daquyr", bodaquyr, 1, 150, 1f, new Vector2(7, 5), tilerong, tiledai);
            }
            else if (kieuvatthe == 15)
            {
                botuimayman.X = Convert.ToInt32(ngaunhien.Next(0, 640 - botuimayman.Width));
                botuimayman.Y = Convert.ToInt32(ngaunhien.Next(200, 480 - botuimayman.Height));
                vtngaunhien = new VatThe(this, vttuimayman, 0, new Vector2(1, 7), "tuimayman", "tuimayman", botuimayman, 1, 0, 1f, new Vector2(19, 14), tilerong, tiledai);
            }
            else if (kieuvatthe == 16)
            {
                bothuocno.X = Convert.ToInt32(ngaunhien.Next(0, 640 - bothuocno.Width));
                bothuocno.Y = Convert.ToInt32(ngaunhien.Next(200, 480 - bothuocno.Height));
                vtngaunhien = new VatThe(this, vtthuocno, 0, new Vector2(1, 7), "thuocno", "thuocno", bothuocno, 1, 0, 1f, new Vector2(0, 0), tilerong, tiledai);
            }
            else if (kieuvatthe == 17)
            {
                boquantai.X = Convert.ToInt32(ngaunhien.Next(0, 640 - boquantai.Width));
                boquantai.Y = Convert.ToInt32(ngaunhien.Next(200, 480 - boquantai.Height));
                vtngaunhien = new VatThe(this, vtquantai, 0, new Vector2(1, 7), "quantai", "quantai", boquantai, 1, 100, 6.3f, new Vector2(50, 18), tilerong, tiledai);
            }
            else if (kieuvatthe == 18)
            {
                bolumia.X = Convert.ToInt32(ngaunhien.Next(0, 640 - bolumia.Width));
                bolumia.Y = Convert.ToInt32(ngaunhien.Next(200, 480 - bolumia.Height));
                vtngaunhien = new VatThe(this, vtlumia, 0, new Vector2(1, 7), "lumia", "lumia", bolumia, 1, 800, 6f, new Vector2(15, 8), tilerong, tiledai);
            }
            else if (kieuvatthe == 19)
            {
                bolongcocaday.X = Convert.ToInt32(ngaunhien.Next(0, 640 - bolongcocaday.Width));
                bolongcocaday.Y = Convert.ToInt32(ngaunhien.Next(200, 480 - bolongcocaday.Height));
                vtngaunhien = new VatThe(this, vtlongcocaday, 0, new Vector2(1, 7), "longcocaday", "longcocaday", bolongcocaday, 1, 300, 3f, new Vector2(14, 11), tilerong, tiledai);
            }
            else if (kieuvatthe == 20)
            {
                bolongcocarong.X = Convert.ToInt32(ngaunhien.Next(0, 640 - bolongcocarong.Width));
                bolongcocarong.Y = Convert.ToInt32(ngaunhien.Next(200, 480 - bolongcocarong.Height));
                vtngaunhien = new VatThe(this, vtlongcocarong, 0, new Vector2(1, 7), "longcocarong", "longcocarong", bolongcocarong, 1, 10, 2f, new Vector2(18, 11), tilerong, tiledai);
            }
            else if (kieuvatthe == 21)
            {
                bochaicocaday.X = Convert.ToInt32(ngaunhien.Next(0, 640 - bochaicocaday.Width));
                bochaicocaday.Y = Convert.ToInt32(ngaunhien.Next(200, 480 - bochaicocaday.Height));
                vtngaunhien = new VatThe(this, vtchaicocaday, 0, new Vector2(1, 7), "chaicocaday", "chaicocaday", bochaicocaday, 1, 100, 5f, new Vector2(12, 9), tilerong, tiledai);
            }
            else if (kieuvatthe == 22)
            {
                bochairong.X = Convert.ToInt32(ngaunhien.Next(0, 640 - bochairong.Width));
                bochairong.Y = Convert.ToInt32(ngaunhien.Next(200, 480 - bochairong.Height));
                vtngaunhien = new VatThe(this, vtchairong, 0, new Vector2(1, 7), "chairong", "chairong", bochairong, 1, 10, 5.5f, new Vector2(38, 8), tilerong, tiledai);
            }
            else if (kieuvatthe == 23)
            {
                bocaitau.X = Convert.ToInt32(ngaunhien.Next(0, 640 - bocaitau.Width));
                bocaitau.Y = Convert.ToInt32(ngaunhien.Next(200, 480 - bocaitau.Height));
                vtngaunhien = new VatThe(this, vtcaitau, 0, new Vector2(1, 7), "caitau", "caitau", bocaitau, 1, 170, 2f, new Vector2(38, 10), tilerong, tiledai);
            }
            else if (kieuvatthe == 24)
            {
                bochiecgiay.X = Convert.ToInt32(ngaunhien.Next(0, 640 - bochiecgiay.Width));
                bochiecgiay.Y = Convert.ToInt32(ngaunhien.Next(200, 480 - bochiecgiay.Height));
                vtngaunhien = new VatThe(this, vtchiecgiay, 0, new Vector2(1, 7), "chiecgiay", "chiecgiay", bochiecgiay, 1, 120, 3f, new Vector2(29, 10), tilerong, tiledai);
            }
            else if (kieuvatthe == 25)
            {
                bochiecguoc.X = Convert.ToInt32(ngaunhien.Next(0, 640 - bochiecguoc.Width));
                bochiecguoc.Y = Convert.ToInt32(ngaunhien.Next(200, 480 - bochiecguoc.Height));
                vtngaunhien = new VatThe(this, vtchiecguoc, 0, new Vector2(1, 7), "chiecguoc", "chiecguoc", bochiecguoc, 1, 125, 3f, new Vector2(29, 19), tilerong, tiledai);
            }
            else if (kieuvatthe == 26)
            {
                bohombimat.X = Convert.ToInt32(ngaunhien.Next(0, 640 - bohombimat.Width));
                bohombimat.Y = Convert.ToInt32(ngaunhien.Next(200, 480 - bohombimat.Height));
                vtngaunhien = new VatThe(this, vthombimat, 0, new Vector2(1, 7), "hombimat", "hombimat", bohombimat, 1, 0, 1f, new Vector2(36, 10), tilerong, tiledai);
            }
            else if (kieuvatthe == 27)
            {
                botomchaynhanh.X = Convert.ToInt32(ngaunhien.Next(0, 640 - botomchaynhanh.Width));
                botomchaynhanh.Y = Convert.ToInt32(ngaunhien.Next(200, 480 - botomchaynhanh.Height));
                vtngaunhien = new VatThe(this, vttomchaynhanh, 1, new Vector2(4, 7), "tomchaynhanh", "tomchaynhanh", botomchaynhanh, 1, 100, 4f, new Vector2(24, 33), tilerong, tiledai);
            }
            else if (kieuvatthe == 28)
            {
                botomvakimcuong.X = Convert.ToInt32(ngaunhien.Next(0, 640 - botomvakimcuong.Width));
                botomvakimcuong.Y = Convert.ToInt32(ngaunhien.Next(200, 480 - botomvakimcuong.Height));
                vtngaunhien = new VatThe(this, vttomvakimcuong, 1, new Vector2(4, 7), "tomvakimcuong", "kimcuong", botomvakimcuong, 1, 700, 5f, new Vector2(24, 33), tilerong, tiledai);
            }
            else if (kieuvatthe == 29)
            {
                bojerrydinhanh.X = Convert.ToInt32(ngaunhien.Next(0, 640 - bojerrydinhanh.Width));
                bojerrydinhanh.Y = Convert.ToInt32(ngaunhien.Next(200, 480 - bojerrydinhanh.Height));
                vtngaunhien = new VatThe(this, vtjerrydinhanh, 1, new Vector2(4, 7), "jerrydinhanh", "jerrydinhanh", bojerrydinhanh, 1, 100, 1f, new Vector2(17, 17), tilerong, tiledai);
            }
            else if (kieuvatthe == 30)
            {
                bodonalchaynhanh.X = Convert.ToInt32(ngaunhien.Next(0, 640 - bodonalchaynhanh.Width));
                bodonalchaynhanh.Y = Convert.ToInt32(ngaunhien.Next(200, 480 - bodonalchaynhanh.Height));
                vtngaunhien = new VatThe(this, vtdonalchaynhanh, 1, new Vector2(4, 7), "donalchaynhanh", "donalchaynhanh", bodonalchaynhanh, 1, 100, 4f, new Vector2(25, 25), tilerong, tiledai);
            }
            else if (kieuvatthe == 31)
            {
                bodonalvakimcuong.X = Convert.ToInt32(ngaunhien.Next(0, 640 - bodonalvakimcuong.Width));
                bodonalvakimcuong.Y = Convert.ToInt32(ngaunhien.Next(200, 480 - bodonalvakimcuong.Height));
                vtngaunhien = new VatThe(this, vtdonalvakimcuong, 1, new Vector2(4, 7), "donalvakimcuong", "kimcuong", bodonalvakimcuong, 1, 750, 4.5f, new Vector2(25, 25), tilerong, tiledai);
            }
            else if (kieuvatthe == 32)
            {
                bodonaldicham.X = Convert.ToInt32(ngaunhien.Next(0, 640 - bodonaldicham.Width));
                bodonaldicham.Y = Convert.ToInt32(ngaunhien.Next(200, 480 - bodonaldicham.Height));
                vtngaunhien = new VatThe(this, vtdonaldicham, 1, new Vector2(1, 3), "donaldicham", "donaldicham", bodonaldicham, 1, 120, 4f, new Vector2(21, 17), tilerong, tiledai);
            }
            else if (kieuvatthe == 33)
            {
                bomickeychaynhanh.X = Convert.ToInt32(ngaunhien.Next(0, 640 - bomickeychaynhanh.Width));
                bomickeychaynhanh.Y = Convert.ToInt32(ngaunhien.Next(200, 480 - bomickeychaynhanh.Height));
                vtngaunhien = new VatThe(this, vtmickeychaynhanh, 1, new Vector2(4, 7), "mickeychaynhanh", "mickeychaynhanh", bomickeychaynhanh, 1, 150, 2f, new Vector2(23, 19), tilerong, tiledai);
            }
            else if (kieuvatthe == 34)
            {
                bomickeyvakimcuong.X = Convert.ToInt32(ngaunhien.Next(0, 640 - bomickeyvakimcuong.Width));
                bomickeyvakimcuong.Y = Convert.ToInt32(ngaunhien.Next(200, 480 - bomickeyvakimcuong.Height));
                vtngaunhien = new VatThe(this, vtmickeyvakimcuong, 1, new Vector2(4, 7), "mickeyvakimcuong", "kimcuong", bomickeyvakimcuong, 1, 800, 3f, new Vector2(23, 19), tilerong, tiledai);
            }
            else if (kieuvatthe == 35)
            {
                bomickeydicham.X = Convert.ToInt32(ngaunhien.Next(0, 640 - bomickeydicham.Width));
                bomickeydicham.Y = Convert.ToInt32(ngaunhien.Next(200, 480 - bomickeydicham.Height));
                vtngaunhien = new VatThe(this, vtmickeydicham, 1, new Vector2(1, 3), "mickeydicham", "mickeydicham", bomickeydicham, 1, 150, 2f, new Vector2(20, 27), tilerong, tiledai);
            }
        }
        protected void LuuTruDuLieu(int nhaclaiquangcao)
        {
            string chuoiluutrochoi = manchoi.ToString() + ";" + nvonglao.diemso.ToString() + ";" + muctieu.ToString() + ";" + nvonglao.dphao.ToString() + ";" + diemkyluc.ToString();
            dungham.LuuDuLieu(tepluutrochoi, chuoiluutrochoi.ToString());
            int maluucaidat = 1;
            if (ngonngu == "tiengviet") maluucaidat = 2;
            maluucaidat = ((maluucaidat * 100 + Convert.ToInt32(kichthuocam * 10)) * 10 + nhaclaiquangcao) * 10 + solansudung;
            dungham.LuuDuLieu(tepluucaidat, maluucaidat.ToString());
        }
        protected void LayDuLieuLuu()
        {
            //bat loi khi doc du lieu luu tru tro choi
            try
            {
                string chuoiluutrochoi = dungham.DocDuLieu(tepluutrochoi);
                if (chuoiluutrochoi.Length > 3)
                {

                    string[] manggiatri = new string[5];
                    int dgt = 0;
                    for (int i = 0; i < chuoiluutrochoi.Length; i++)
                    {
                        if (chuoiluutrochoi.Substring(i, 1) != ";")
                        {
                            manggiatri[dgt] = manggiatri[dgt] + chuoiluutrochoi.Substring(i, 1);
                        }
                        else dgt++;
                    }
                    manchoi = Convert.ToInt32(manggiatri[0]);
                    diemsoluu = Convert.ToDouble(manggiatri[1]);
                    muctieu = Convert.ToDouble(manggiatri[2]);
                    sophaoluu = Convert.ToInt32(manggiatri[3]);
                    diemkyluc = Convert.ToDouble(manggiatri[4]);
                    if (diemkyluc < diemsoluu) diemkyluc = diemsoluu;
                }
            }
            catch
            {
                manchoi = 1;
                diemsoluu = 500;
                muctieu = 0;
                sophaoluu = 0;
                diemkyluc = 500;
            }
            //bat loi khi doc du lieu luu tru cai dat
            try
            {
                maluucaidat = Convert.ToDouble(dungham.DocDuLieu(tepluucaidat));
                string chuoimaluucaidat = maluucaidat.ToString();
                if (chuoimaluucaidat.Length == 5)
                {

                    if (chuoimaluucaidat.Substring(0, 1) == "2") ngonngu = "tiengviet";
                    if (chuoimaluucaidat.Substring(3, 1) == "0") nhacquangcao = 0;
                    kichthuocam = Convert.ToInt32(chuoimaluucaidat.Substring(1, 2)) / 10f;
                    solansudung = Convert.ToInt32(chuoimaluucaidat.Substring(4, 1));
                }

            }
            catch
            {
                ngonngu = "english";
                kichthuocam = 0.5f;
                nhacquangcao = 1;
                solansudung = 0;
            }
            if (nvonglao != null)
            {
                nvonglao.diemso = diemsoluu;
                nvonglao.dphao = sophaoluu;
            }
        }
        protected void VeBangQuangCao()
        {
            if (bangquangcao == "co")
            {
                if (ngonngu == "english") haquangcaoa.HienThiThuong(spriteBatch);
                else haquangcaov.HienThiThuong(spriteBatch);
                hachapnhan.HienThiThuong(spriteBatch);
                hakhongnhaclai.HienThiThuong(spriteBatch);
                hachapnhan.HienThiNhapNhay(spriteBatch);
                hakhongnhaclai.HienThiNhapNhay(spriteBatch);
            }
        }
        protected void XuLyQuangCao()
        {
            if (hakhongnhaclai.slchon != 1)
                hachapnhan.KichChonNhapNhay(trochuothientai, trochuottruocdo, 1, ref luachon, kichthuocam);
            if (hachapnhan.slchon != 1)
                hakhongnhaclai.KichChonNhapNhay(trochuothientai, trochuottruocdo, 1, ref luachon, kichthuocam);
            if (luachon == "nutchapnhan")
            {
                LuuTruDuLieu(1);
                dungham.QuangBaSanPham();
                //this.Exit();
                bangquangcao = "rong";
                nhacquangcao = 0;
            }
            else if (luachon == "nutkhongnhaclai")
            {
                LuuTruDuLieu(0);
                dungham.QuangBaSanPham();
                //this.Exit();
                bangquangcao = "rong";
                nhacquangcao = 0;
            }
        }
        private void NapLaiDuLieu()
        {
            if (App.naplai)
            {
                NapLaiAnhChuoiKyTu();
                App.naplai = false;
            }
        }
        private void NapTuyChinh()
        {
            Texture2D anhdunglait = Content.Load<Texture2D>("HinhAnh/TuyChinh/1");
            Texture2D anhdunglais = Content.Load<Texture2D>("HinhAnh/TuyChinh/2");
            Texture2D anhbatam = Content.Load<Texture2D>("HinhAnh/TuyChinh/3");
            Texture2D anhtatam = Content.Load<Texture2D>("HinhAnh/TuyChinh/4");
            Texture2D anhtamdung = Content.Load<Texture2D>("HinhAnh/TuyChinh/5");
            Texture2D anhchoitiep = Content.Load<Texture2D>("HinhAnh/TuyChinh/6");
            Texture2D anhnensophao = Content.Load<Texture2D>("HinhAnh/TuyChinh/7");
            Rectangle boanhdunglai = dungham.BoHinhAnh(599, 36, 20, 20, tilerong, tiledai);
            Rectangle boanhdungtiep = dungham.BoHinhAnh(543, 36, 20, 20, tilerong, tiledai);
            Rectangle boanhbattat = dungham.BoHinhAnh(486, 36, 20, 20, tilerong, tiledai);
            Rectangle boanhnensophao = dungham.BoHinhAnh(251, 155, 25, 25, tilerong, tiledai);
            hadungchoi = new HinhAnh("dungchoi", boanhdunglai, anhdunglait, anhdunglais, amchon, null);
            hadungtiep = new HinhAnh("dungtiep", boanhdungtiep, anhtamdung, anhchoitiep, amchon, null);
            habattatam = new HinhAnh("battatam", boanhbattat, anhbatam, anhtatam, amchon, null);
            hanensophao = new HinhAnh("anhnensophao", boanhnensophao, anhnensophao, anhnensophao, null, null);
            kichthuocam = amhientai;
            trangthaitamdung = 0;
        }
        private void VeAnhDiemTienTrinh()
        {
            adiemtientrinh = bokytu[10].XuatAnhKyTu(nvonglao.diemso.ToString() + "/" + muctieu.ToString(), 0, 0, 1, 1, 1, 1, Color.Transparent);
        }
        private void VeAnhDiemManChoi()
        {
            adiemmanchoi = bokytu[3].XuatAnhKyTu(manchoi.ToString(), 50, 30, 1, 1, 2, 2, Color.Transparent);
        }
        private void VeAnhThoGianChoi()
        {
            athoigianchoi = bokytu[4].XuatAnhKyTu(thoigianchoi.ToString(), 30, 30, 1, 1, 2, 2, Color.Transparent);
        }
        private void VeAnhSoPhaoNo()
        {
            asophaono = bokytu[5].XuatAnhKyTu(nvonglao.dphao.ToString(), 30, 30, 1, 1, 2, 2, Color.Transparent);
        }
        private void VeAnhChuPhienBan()
        {
            achuphienban = bokytu[0].XuatAnhKyTu(phienbangame.ToString(), 300, 30, 1, 1, 3, 2, Color.Transparent);
        }
        private MouseState GetMouseState()
        {
            TouchCollection TouchState = TouchPanel.GetState();
            MouseState CurrentMouseState = new MouseState();
            foreach (TouchLocation tl in TouchState)
            {
                CurrentMouseState = new MouseState((int)tl.Position.X, (int)tl.Position.Y, 0, ButtonState.Pressed, ButtonState.Released, ButtonState.Released, ButtonState.Released, ButtonState.Released);
            }
            return CurrentMouseState;
        }
        public void NapBoKyTu(ref Texture2D[] boanhkytucat, ref int[] bodorongkytumoi, ref string[] bogiatrikytu, ref Texture2D anhkytucham, string duongdanbokytu, int[] dorongbokytu, string[] giatribokytu, int vitrianhdaucham)
        {
            int soluong = dorongbokytu.Length;
            Array.Resize(ref boanhkytucat, soluong);
            Array.Resize(ref bodorongkytumoi, soluong);
            Array.Resize(ref bogiatrikytu, soluong);
            bodorongkytumoi = dorongbokytu;
            bogiatrikytu = giatribokytu;
            for (int i = 0; i < soluong; i++) boanhkytucat[i] = Content.Load<Texture2D>(duongdanbokytu + "/" + (i + 1));
            anhkytucham = Content.Load<Texture2D>(duongdanbokytu + "/" + vitrianhdaucham.ToString());
        }
        private void NapGameLienQuan()
        {
            if (App.mang)
            {
                Texture2D iconfacebook = Content.Load<Texture2D>("HinhAnh/IconGames/Facebook");
                Texture2D iconfacebookkh = Content.Load<Texture2D>("HinhAnh/IconGames/FacebookKH");
                ifacebook = new MChayAnhThuong(1, iconfacebook, iconfacebookkh, new Vector2(10, 406), amchon, tilerong, tiledai);
                Texture2D icontwitter = Content.Load<Texture2D>("HinhAnh/IconGames/Twitter");
                Texture2D icontwitterkh = Content.Load<Texture2D>("HinhAnh/IconGames/TwitterKH");
                itwitter = new MChayAnhThuong(1, icontwitter, icontwitterkh, new Vector2(84, 406), amchon, tilerong, tiledai);
                Texture2D iconemail = Content.Load<Texture2D>("HinhAnh/IconGames/Email");
                Texture2D iconemailkh = Content.Load<Texture2D>("HinhAnh/IconGames/EmailKH");
                iemail = new MChayAnhThuong(1, iconemail, iconemailkh, new Vector2(158, 406), amchon, tilerong, tiledai);
                Texture2D icondaovang = Content.Load<Texture2D>("HinhAnh/IconGames/DaoVang");
                Texture2D icondaovangkh = Content.Load<Texture2D>("HinhAnh/IconGames/DaoVangKH");
                idaovang = new MChayAnhThuong(1, icondaovang, icondaovangkh, new Vector2(232, 406), amchon, tilerong, tiledai);
                Texture2D iconvuaxocdia = Content.Load<Texture2D>("HinhAnh/IconGames/VuaXocDia");
                Texture2D iconvuaxocdiakh = Content.Load<Texture2D>("HinhAnh/IconGames/VuaXocDiaKH");
                ivuaxocdia = new MChayAnhThuong(1, iconvuaxocdia, iconvuaxocdiakh, new Vector2(306, 406), amchon, tilerong, tiledai);
                Texture2D iconruntodeath = Content.Load<Texture2D>("HinhAnh/IconGames/RunToDeath");
                Texture2D iconruntodeathkh = Content.Load<Texture2D>("HinhAnh/IconGames/RunToDeathKH");
                iruntodeath = new MChayAnhThuong(1, iconruntodeath, iconruntodeathkh, new Vector2(380, 406), amchon, tilerong, tiledai);
            }
        }
        private void KichHoatGameLienQuan()
        {
            if (App.mang)
            {
                ifacebook.KichHoatThuong(1, trochuothientai, trochuottruocdo, "gfacebook", ref luachon, kichthuocam);
                itwitter.KichHoatThuong(1, trochuothientai, trochuottruocdo, "gtwitter", ref luachon, kichthuocam);
                iemail.KichHoatThuong(1, trochuothientai, trochuottruocdo, "gemail", ref luachon, kichthuocam);
                idaovang.KichHoatThuong(1, trochuothientai, trochuottruocdo, "gdaovang", ref luachon, kichthuocam);
                ivuaxocdia.KichHoatThuong(1, trochuothientai, trochuottruocdo, "gvuaxocdia", ref luachon, kichthuocam);
                iruntodeath.KichHoatThuong(1, trochuothientai, trochuottruocdo, "gruntodeath", ref luachon, kichthuocam);
                if (luachon == "gfacebook")
                {
                    ShareLinkTask sfacebook = new ShareLinkTask();
                    sfacebook.Title = "Share Facebook";
                    sfacebook.LinkUri = new Uri("http://www.windowsphone.com/en-us/store/app/gold-miner/f9357656-845b-4cc6-ab41-f487f4d0a5f0", UriKind.Absolute);
                    sfacebook.Message = "Share the game with your friends. Thank you!";
                    sfacebook.Show();
                }
                else if (luachon == "gtwitter")
                {
                    ShareLinkTask stwitter = new ShareLinkTask();
                    stwitter.Title = "Share Twitter";
                    stwitter.LinkUri = new Uri("http://www.windowsphone.com/en-us/store/app/gold-miner/f9357656-845b-4cc6-ab41-f487f4d0a5f0", UriKind.Absolute);
                    stwitter.Message = "Share the game with your friends. Thank you!";
                    stwitter.Show();
                }
                else if (luachon == "gemail")
                {
                    EmailComposeTask semail = new EmailComposeTask();
                    semail.Subject = "http://www.windowsphone.com/en-us/store/app/gold-miner/f9357656-845b-4cc6-ab41-f487f4d0a5f0";
                    semail.Body = "Share the game with your friends. Thank you!";
                    semail.Show();
                }
                else if (luachon == "gdaovang")
                {
                    MarketplaceDetailTask quangcao = new MarketplaceDetailTask();
                    quangcao.ContentIdentifier = "f9357656-845b-4cc6-ab41-f487f4d0a5f0";
                    quangcao.ContentType = MarketplaceContentType.Applications;
                    quangcao.Show();
                }
                else if (luachon == "gvuaxocdia")
                {
                    MarketplaceDetailTask quangcao = new MarketplaceDetailTask();
                    quangcao.ContentIdentifier = "ea8e7cf5-0175-496e-be5b-1a8085fcfe2a";
                    quangcao.ContentType = MarketplaceContentType.Applications;
                    quangcao.Show();
                }
                else if (luachon == "gruntodeath")
                {
                    MarketplaceDetailTask quangcao = new MarketplaceDetailTask();
                    quangcao.ContentIdentifier = "7e575f5c-63ce-4913-84ae-acfac342df9e";
                    quangcao.ContentType = MarketplaceContentType.Applications;
                    quangcao.Show();
                }
            }
        }
        private void HienThiGameLienQuan(SpriteBatch nenve)
        {
            if (App.mang)
            {
                ifacebook.HienThiThuong(nenve);
                itwitter.HienThiThuong(nenve);
                iemail.HienThiThuong(nenve);
                idaovang.HienThiThuong(nenve);
                ivuaxocdia.HienThiThuong(nenve);
                iruntodeath.HienThiThuong(nenve);
            }
        }
        public void NapLaiAnhChuoiKyTu()//danh cho truong hop giai phong ram thi phai goi lai
        {
            try
            {
                achuphienban = bokytu[0].PhucHoiHinhAnh();
                anhthongtinvatpham = bokytu[1].PhucHoiHinhAnh();
                adiemmanchoi = bokytu[3].PhucHoiHinhAnh();
                athoigianchoi = bokytu[4].PhucHoiHinhAnh();
                asophaono = bokytu[5].PhucHoiHinhAnh();
                anhcauhoithoai = bokytu[6].PhucHoiHinhAnh();
                anhchuthongbao = bokytu[7].PhucHoiHinhAnh();
                anhdiemsonhanvat = bokytu[8].PhucHoiHinhAnh();
                anhsomanchoi = bokytu[9].PhucHoiHinhAnh();
                adiemtientrinh = bokytu[10].PhucHoiHinhAnh();
                if(nvonglao!=null) nvonglao.PhucHoiChuoiKyTu();
            }
            catch { }
        }
    }
}